LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem in assigning static IP address to ethernet port in Raspberry Pi? (https://www.linuxquestions.org/questions/linux-newbie-8/problem-in-assigning-static-ip-address-to-ethernet-port-in-raspberry-pi-4175615806/)

vishnumc 10-17-2017 02:32 AM

Problem in assigning static IP address to ethernet port in Raspberry Pi?
 
I am having Rpi3 which uses debian stretch version of OS. In this version, the network interfaces can assign static IP using two methods.

1. First is by editing dhcpcd.conf

interface eth1
static ip_address=192.168.42.1/24
static routers=192.168.42.1
static domain_name_servers=192.168.42.1

2. Second is by editing /etc/network/interfaces file and disable the dhcpcd.

auto eth0
iface eth0 inet dhcp

allow-hotplug eth1
iface eth1 inet static
address 192.168.42.1
netmask 255.255.255.0
network 192.168.42.0
broadcast 192.168.42.255

But doing it by first method, ifconfig command shows eth1 port is not assigned with static IP until a device is connected through the port.

But by second method, ifconfig command shows eth1 port assigned with static IP even if there is no connected device.

What is the actual difference in between them?
I am new to linux networking and i hope you help me?

bloodh101 10-17-2017 03:24 AM

You may need to disable dhcpcd
Code:

sudo systemctl disable dhcpcd
Also have a look at this.

vishnumc 10-17-2017 04:17 AM

Quote:

Originally Posted by bloodh101 (Post 5770783)
You may need to disable dhcpcd
Code:

sudo systemctl disable dhcpcd
Also have a look at this.

Sir, In both cases i can configure the static IP. But for first method that is by using dhcpcd file, static IP is assigned only when a device is connected to the port. I used ifconfig to view the IP but inet addrs is not shown until i connected my laptop to eth1 port of Rpi.

But this problem is not present in the second method. In the second method, i have already disabled the dhcpcd by sudo systemctl disable dhcpcd. Static IP is assigned to eth1 port even if i haven't connected my laptop.

michaelk 10-17-2017 06:31 AM

The DHCP client checks for a link status but networking startup does not.

As stated the second method eth1 is assigned an IP address regardless if connected to anything.

vishnumc 10-17-2017 06:35 AM

Quote:

Originally Posted by michaelk (Post 5770829)
The DHCP client checks for a link status but networking startup does not.

As stated the second method eth1 is assigned an IP address regardless if connected to anything.

So, how to do it using the dhcpcd file. Is there any way to achieve the same as in interfaces file?

michaelk 10-17-2017 06:48 AM

Using the nolink option might work but it seems illogical to want to use the dhcp client to set a static IP address instead of the interfaces file.

vishnumc 10-17-2017 06:54 AM

Quote:

Originally Posted by michaelk (Post 5770837)
Using the nolink option might work but it seems illogical to want to use the dhcp client to set a static IP address instead of the interfaces file.

Please see the default /etc/network/interfaces file in the Stretch OS.

Quote:

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
Here mentioned that for setting static IPs consult /etc/dhcpcd.conf. If it is illogical why the official document inform us to consult dhcpcd.conf for static IPs.

If i am wrong please let me know

michaelk 10-17-2017 07:00 AM

I don't know yet. I have not tried running Stretch but would of expected it to be similar to previous versions.

vishnumc 10-17-2017 07:07 AM

:-( :-(


All times are GMT -5. The time now is 05:21 PM.