25

By default Ubuntu uses DHCP and Gnome NetworkManger to configure interfaces. This is not optimal in many cases.

How to configure a desktop machine for a static IP address that applies to all users?

Additional background: For 99.9% of users a static DHCP entry is probably the easiest solution, however I have found a conflict with mythtv-background process and any changes to the eth0 interface. If the interface is brought up/down after mythtv is running, it hangs the process (which also broke system suspend). So my questions really needs a static IP address, where the interface is brought up with a known IP, and stays up permanently.

Braiam
  • 69,112
cmcginty
  • 6,016

4 Answers4

21

Right click nm, choose Edit connections... find your interface, click Edit..., click IPv4 Settings, choose Manual and configure your interface.

An alternative would be to edit /etc/network/interfaces. an example configuration would be:

auto eth0
iface eth0 inet static
   address 192.168.1.1
    netmask 255.255.255.0
    gateway 192.168.1.1

then run

/etc/init.d/networking restart

Keep in mind that this will deactivate nm for this interface and you will have to delete (or uncomment) the entries to activate nm again.

Edit (see Casey's post): You also have to set a DNS after editing /etc/network/interfaces:

Set one or more desired nameserver in /etc/resolv.conf:

nameserver 192.168.1.1

sBlatt
  • 4,619
5

Update /etc/networking/interfacesto set the static address:

auto eth0
iface eth0 inet static
    address 192.168.0.10
    netmask 255.255.255.0
    gateway 192.168.0.1

Set one or more desired nameserver in /etc/resolv.conf:

nameserver 192.168.0.1

You must prevent gnome-network-manager from attempting to hijack the eth0 connection:

sudo apt-get remove network-manager network-manager-gnome

Assign static IP address by restarting the networking sub-system:

sudo invoke-rc.d networking restart
cmcginty
  • 6,016
1

If you have a little router logged into it, (something like http://192.168.1.1 from you browser), record current DNS server addresses. Reserver one more IP address from DHCP, (something like 192.168.1.200-192.168.1.210), or disable DHCP all together.

From Ubuntu menu: System --> Preferences --> Network Connections --> Auto eth0 --> edit --> IPV4 Settings --> Change it to Manual --> add ip, (something like 192.168.1.200 what you reservered above), netmask 255.255.255.0,, and router inside address for default route, (something like 192.168.1.1 what you used to log into it) --> Enter the DNS server addresses you recorded at the bottom of the window.

1

1) check which interface should be configed, assume the interface you want to change is eth0 in this case:

$ ip addr

2) open and edit /etc/network/interface:

$ sudo gedit /etc/network/interface

3) add the following lines to the file /etc/network/interface:

auto eth0
iface eth0 inet static
address 192.168.1.22
netmask 255.255.255.0
gateway 192.168.1.1

3) restart your interface with command ifdown and ifup:

$ sudo ifdown --force eth0
$ sudo ifup --force eth0

PS: use $ sudo systemctl restart networking or $ sudo ifup eth0 may do not working when other networking tools are being used, please also check Can't ifdown eth0 (main interface)

realhu
  • 1,719
  • 1
  • 11
  • 8