LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-17-2017, 03:32 AM   #1
vishnumc
LQ Newbie
 
Registered: Jul 2017
Posts: 5

Rep: Reputation: Disabled
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?
 
Old 10-17-2017, 04:24 AM   #2
bloodh101
LQ Newbie
 
Registered: Oct 2017
Distribution: Arch
Posts: 5

Rep: Reputation: Disabled
You may need to disable dhcpcd
Code:
sudo systemctl disable dhcpcd
Also have a look at this.

Last edited by bloodh101; 10-17-2017 at 04:25 AM.
 
Old 10-17-2017, 05:17 AM   #3
vishnumc
LQ Newbie
 
Registered: Jul 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bloodh101 View Post
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.
 
Old 10-17-2017, 07:31 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,393

Rep: Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087
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.
 
Old 10-17-2017, 07:35 AM   #5
vishnumc
LQ Newbie
 
Registered: Jul 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
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?
 
Old 10-17-2017, 07:48 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,393

Rep: Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087Reputation: 3087
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.
 
Old 10-17-2017, 07:54 AM   #7
vishnumc
LQ Newbie
 
Registered: Jul 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
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
 
Old 10-17-2017, 08:00 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 19,393

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

Last edited by michaelk; 10-17-2017 at 08:02 AM.
 
Old 10-17-2017, 08:07 AM   #9
vishnumc
LQ Newbie
 
Registered: Jul 2017
Posts: 5

Original Poster
Rep: Reputation: Disabled
:-( :-(
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning static private IP address to Virtual machine (Vmware) tt1187 Linux - Newbie 3 03-10-2014 05:26 PM
Assigning printer a static IP-address with dhcpcd (.conf)? Paraply Linux - Networking 18 12-23-2011 09:25 AM
[SOLVED] Problem on assigning static ip address.. RHEL 5 as guest OS on Virtualbox odessy Linux - Newbie 4 08-28-2009 12:51 PM
Problem on assigning static ip address.. RHEL 5 as guest OS on Virtualbox odessy Linux - Networking 1 08-28-2009 10:22 AM
Assigning a static IP address hangs system??? dmangal Linux - Networking 2 05-16-2007 05:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration