Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
1  
As a side note, you can use DHCP reservation in your router, which will reserve the IP for your computer by identifying it by the NIC's MAC address, and this will literally behave as if a Static IP is set. –  LFC_fan Oct 14 '10 at 10:07
    
thanks good tip for someone just looking for the consistent IP address –  Casey Oct 14 '10 at 20:07
add comment

3 Answers 3

up vote 16 down vote accepted

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

share|improve this answer
    
after 'networking restart', only lo interface comes up –  Casey Oct 14 '10 at 8:30
1  
The interface name (eth0 in sBlatt's example) might be different on your PC: eth0 is the usual name for the first wired ethernet interface; there is no standard for naming wireless interfaces. The command ip link show will display a list of network interfaces, along with their relevant parameters. –  Riccardo Murri Oct 14 '10 at 11:43
    
Alternatively, after right clicking on network manager and choosing "Edit Connections", choose whether it will be wired or wireless, then click "Add". After adding the static IP as desired, close all the dialogs then left-click on the network manager icon. You'll now have the option of "Auto Eth0" which is DHCP, and the connection you added manually. You can do this multiple times, building up a list of different static IP addresses for each location or circumstance you might find yourself in. –  Scaine Oct 14 '10 at 13:18
    
@Riccardo, yes my interface is eth0. Like I said, only making the changes in interfaces is not a working solution for me –  Casey Oct 14 '10 at 20:10
    
@Scain, do changes in network manager apply to all users? My problem was that switching users would bring the interface down and back up. That is not really static. –  Casey Oct 14 '10 at 20:11
show 2 more comments

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
share|improve this answer
5  
Do not remove network-manager! You run a risk of ending up with no internet connection at all, if you make some mistakes in setting up the static IP (and you are not able to correct them). –  Riccardo Murri Oct 14 '10 at 11:36
1  
You can tell NetworkManager not to automatically bring an interface up (right-click -> Edit connections... -> select one -> Edit... -> click on the Connect automatically checkbox); this way you can still have network manager installed and manually activate interfaces via ifup/ifdown –  Riccardo Murri Oct 14 '10 at 21:26
2  
Besides, my comment was there to alert users with the same problem that removing network-manager is a risky route to take. You are evidently able to manage your network connection and troubleshoot problems; other readers of this question might not... –  Riccardo Murri Oct 14 '10 at 21:28
add comment

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.

share|improve this answer
    
I updated my question a little to explain why this solution will not work for me. I need the interface to stay up permanently. –  Casey Oct 14 '10 at 20:14
    
It will always come up @ this address when you boot, (in this example 192.168.0.200), And stay up permanently. Your router is not setting it anymore via DHCP. It is hard coded into the computer. –  stevehendo34 Oct 14 '10 at 22:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.