16
2
How to setup static IP address under Ubuntu 14.04 Trusty?
(NOTE, the question was asked for "14.04 Trusty", but it is still working for now, 16.04 LTS Xenial)
My setting is not working. What special about Ubuntu 14.04 Trusty is that I found it now using the "source-directory" keyword to source multiple files at once (Ref: http://manpages.debian.org/cgi-bin/man.cgi?query=interfaces&apropos=0&sektion=0&manpath=Debian+unstable+sid&format=html&locale=en):
$ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
So I prepared my static IP address setting as this:
$ cat /etc/network/interfaces.d/eth
auto eth0
iface eth0 inet static
address 192.168.2.100
netmask 255.255.255.0
gateway 192.168.2.0
# add a 2nd ip address
post-up ip addr add dev eth0 192.168.2.101/24
pre-down ip addr del dev eth0 192.168.2.101/24
However, it has an extensive delay during boot up. I saw the boot up message saying something like "Bring up Network", then after a long delay later, saying something again like "Waiting for 60 more seconds to bring up Network". After that 60 more seconds delay, the boot up messages start to fly again. However, when the system finally boot, and I check the ip addr
output, the second static IP address that I configured is not there.
Am I missing something?
UPDATE:
Thanks everyone for pointing out that my gateway was wrong so I changed it to 192.168.2.1
, and the long delay in boot is gone. Now I'm getting into a new problem.
For my Ubuntus prior to 14.04 Trusty, the above change is sufficient to switch from dynamic IP to static IP. However, with my new Ubuntu 14.04 Trusty, the system boots up with no IPv4 addresses:
$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:xx:xx:xx:xx:ef
inet6 addr: fe80::xxx:xxxx:xxxx:98ef/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1 errors:0 dropped:0 overruns:0 frame:0
TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:250 (250.0 B) TX bytes:11552 (11.5 KB)
It also gives errors when I was trying to bring down the device:
% ifdown eth0
RTNETLINK answers: No such process
RTNETLINK answers: Cannot assign requested address
I am able to bring up the device afterward though, and then ifconfig
& ip addr
give the correct output. However, the IPv4 address will be gone after a short while.
How to tell network manager that I've switched my eth device from dynamic IP to static IP? (Command-line and file tweaking preferred over GUI tweaking).
This is XUbuntu 14.04. Thanks
UPDATE2:
Use /etc/network/interfaces
instead. Details in my own answer.
For automatically setting the /etc/network/interfaces
file, take a look here.
I generally don't use network manager..... – mdpc – 2014-05-10T20:39:09.163
I have
network-manager
&network-manager-gnome
installed in my Ubuntu 13.10, and my static IP address setup is fine. – xpt – 2014-05-10T21:07:48.730Strange, I am also running 14.04 and static address works (though I haven't configured a second IP). – user1301428 – 2014-05-10T22:40:34.533
@user1301428, does your setting have more items? I used to do this, http://superuser.com/questions/736037/the-network-setting-for-etc-network-interfaces-for-static-ip-of-a-supernet-addr, but figured from the replies that I can omit many things. Would that be the case, or you are doing some more things than the mere things in my OP?
– xpt – 2014-05-11T01:22:54.710My
/etc/network/interfaces
file only contains theiface
,address
,netmask
,gateway
,network
,broadcast
anddns-nameservers
directives – user1301428 – 2014-05-11T17:49:47.467That's what I used to do, as posted in above link. Since my new setting is working now, we can conclude that
network
, &broadcast
are indeed not necessary. As fordns-nameservers
I don't think it even works. Try to set to a different value, say8.8.8.8
, andservice networking restart
(or if down & up), thencat /etc/resolv.conf
ordig google.ca
. I bet it will never pick up values from thedns-nameservers
entry. – xpt – 2014-05-11T19:57:32.680