Why can't I set a static IP address for my Linux box?
If you are using a desktop version of Ubuntu, with a graphical network-manager tool installed, then you should not define the connection in the /etc/network/interfaces file.
Instead, open the connection via the nm-applet on the desktop (or by invoking nm-connection-editor
from a terminal), navigate to the IPv4 settings tab, and set the connection mode to Manual using the drop-down selection box. Then add your desired IP and DNS settings in the boxes provided.
You should then revert any edits to your /etc/network/interfaces file (so that it contains only the lo
definition lines) and either restart both the networking
and network-manager
services or reboot the machine.
You should also make sure that the chosen static IP address is outside the DHCP pool assigned by your router - in fact, you may find it simpler to keep a DHCP configuration on the machine, and reserve a particular IP for it on the router, if it supports DHCP address reservation.
If you really want to keep the GUI network-manager
, but define your interface via /etc/network/interfaces, then you could try editing /etc/NetworkManager/NetworkManager.conf, changing
[ifupdown]
managed=false
to
[ifupdown]
managed=true
and then making sure there are no other competing connections defined in the /etc/NetworkManager/system-connections/ directory (where 'competing' means 'using the same interface as'). This should allow you to see and control the connections in /etc/network/interfaces under the GUI network-manager applet.
Alternatively you could remove the network-manager package altogether.
Related videos on Youtube
Parker Kemp
Updated on September 18, 2022Comments
-
Parker Kemp over 1 year
I'm trying to set up a static local IP address for my Linux computer for port-forwarding purposes. As per every single guide that exists on this subject, I've edited my
/etc/network/interfaces
and/etc/resolv.conf
files accordingly. However, upon rebooting, any changes I've made toresolv.conf
are erased and the file is blank (except for the comment that warns me of exactly that).As a result, I'm unable to resolve hostnames (
ping google.com
fails, for example). In fact, I can't even ping valid IP addresses ("Destination Host Unreachable").Although
ifconfig
seems to reflect all the settings I put in/etc/network/interfaces
, I am unable to access the Internet whatsoever, nor can I access the machine using SSH or FTP from another machine.Here's my
/etc/network/interfaces
:# interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.0.64 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.1 dns-nameservers 192.168.0.1 8.8.8.8
Here's what
ifconfig
gives me:eth0 Link encap:Ethernet HWaddr 00:25:90:57:7c:65 inet addr:192.168.0.64 Bcast:192.168.0.255 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:20 Memory:fba00000-fba20000 eth1 Link encap:Ethernet HWaddr 00:25:90:57:7c:64 inet addr:192.168.0.10 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::225:90ff:fe57:7c64/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:252 errors:0 dropped:0 overruns:0 frame:0 TX packets:106 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:54010 (54.0 KB) TX bytes:15731 (15.7 KB) Interrupt:16 Memory:fb900000-fb920000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:94 errors:0 dropped:0 overruns:0 frame:0 TX packets:94 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:8088 (8.0 KB) TX bytes:8088 (8.0 KB)
Why is this happening and how can I fix it?
-
Parker Kemp over 10 yearsWhat I'm using is actually Xubuntu on a machine designed specifically to run as a server. It does have a GUI which I can access if I have to, but generally I just access it via SSH from another computer. That's the reason I'm trying to do this all through command line. Are you just saying it's easier to use the GUI, or are you saying that the presence of the GUI nullifies the /etc/network/interfaces method?
-
steeldriver over 10 yearsIt doesn't nullify it exactly, however the two different services are known not to play well together.
-
Parker Kemp over 10 yearsOK, I've opted to uninstall network-manager via
sudo apt-get purge network-manager
. I rebooted, and am still having the same issues.eth1
no longer shows up underifconfig
(which I expected), but it still can't seem to connect viaeth0
. You mentioned making sure the IP address is outside of the DHCP pool of the router... I was unaware this was a factor. How can I figure out the range of the DHCP pool, and just out of curiosity, why does this matter? -
steeldriver over 10 yearsIf your static IP is not outside the router's address pool, then there's nothing to stop it assigning the same IP to another host via DHCP, which will cause an addressing conflict. You would need to go into your router's management web interface to check that, however if it's just a small home LAN then an address conflict is unlikely. Can you narrow down where the connection is failing i.e. can you ping your gateway / router by IP? ping another host in the LAN by IP? ping an external host by IP? and by name? ping everywhere but not browse the internet?
-
Parker Kemp over 10 yearsThanks for sticking around :). I hadn't even thought to try pinging the router yet, but I did just now, and I'm still getting "Destination Host Unreachable." So no, it's not even connecting to the router.
-
steeldriver over 10 yearsWell this isn't the best forum for step-by-step troubleshooting but the first thing that stands out is that your original (presumably functional) DHCP connection using network-manager was eth1 not eth0 - so do you have 2 physical ethernet ports? are you sure you're plugged in to the same one you are configuring? Are you sure both work? Perhaps changing eth0 to eth1 in /etc/network/interfaces is all that's required.
-
Parker Kemp over 10 yearsI feel so dumb now. I had always wondered what the difference was between eth0 and eth1. Now I know (and yes, that fixed it).