In general, your process will be:
- Stop network-manager
- bring the interface down
- assign the address and netmask (using ifconfig)
- optionally create a route to a gateway if the interface is the one that will access the internet (using route)
- bring the interface back up
- and either:
- If DHCP-managed IP address assignment as defined in
/etc/network/interfaces
:
- do nothing.
service network-manager force-reload
- If Static IP address assignment as defined in
/etc/network/interfaces
:
- change (or define) the IP, netmask, broadcast, gateway as needed
service network-manager start
Of course, network-manager is capable of assigning static routes too. Just define your static route in network-manager GUI and then service network-manager force-reload
at terminal. Done.
Or switch back to DHCP-assigned dynamically by removing the static route definition from network-manager GUI, then service network-manager force-reload
at terminal. Done.
Or you can do it...
The harder way
Which also happens to be the logically flawless, sure-fire way.
These instructions assume your interface is "eth0". If it's not, you'll need to change all commands and areas entered to reflect your interface.
First, check if network-manager is running:
service network-manager status
If it is running, right-click on Network-Manager and click "Edit connections...". Select the [interface] you're having trouble with, and click "Edit...". Click on the "IPv4 Settings" tab. If you see any entries under "Addresses", delete them. "Save" the settings, and close Network-Manager out.
Then, at a terminal, these four command strings, replace brackets and inner bounds area with value:
sudo service network-manager stop;
sudo ifconfig eth0 down;
sudo ifconfig eth0 [static IP you want] netmask [netmask; generally 255.255.255.0] up;
ifconfig eth0;
You should see that your interface now has the address you want, but we're not done. To make the settings persistent (i.e., across reboots), you'll need to edit (as root) /etc/network/interfaces
, and either find the section related to your [interface], or you'll add a new section, separating each section (each "section" defines one interface) by a blank line:
Example (If already exists in file, looks like or similar to):
auto eth0
iface eth0 inet dhcp
Example (Change to this, or add if doesn't exist):
auto eth0
iface eth0 inet static
address [ip address goes here]
netmask [netmask goes here]
broadcast [for netmask 255.255.255.0, this should be x.x.x.255 where x from IP]
(optional here, if this is will be your internet interface, "gateway [gateway addr]" goes here)
Of particular note is that you don't want dhcp
-assigned IP, you want static
-IP. Note the difference in structure between the above two examples.
Save it.
Now if this interface will be meant for internet or external routing (i.e., communication on the interface needs to be able to access IPs outside of the network of the interface, which is defined by your netmask ultimately), then:
At terminal:
sudo route add default gw ["inside local" IP address of your router or other gateway]
Verify your settings are correct with:
sudo ifconfig eth0|grep addr && route|grep UG|awk '{print "Gateway:", $2, "Interface:", $8}';
Now:
sudo service network-manager start
...to restart network-manager. At this point you should be good to go.
In the future:
If you need to change your static IP to another static IP after this, it's as simple as sudo service network-manager stop
as exampled above, sudo ifconfig eth0 down
, edit /etc/network/interfaces
as exampled above and changing the IP address to taste, sudo ifconfig eth0 [ip address] netmask [netmask] up
as exampled above, and then sudo network-manager start
as exampled above, in that order.
If instead you want DHCP to assign IP addresses automatically to the interface, it's as simple as sudo service network-manager stop
as exampled above, sudo ifconfig eth0 down
, edit /etc/network/interfaces
as exampled above and remove the lines address, netmask, broadcast, gateway, and change the part that says static
to dhcp
, sudo ifconfig eth0 0.0.0.0 netmask 255.255.255.0 up
, sudo service network-manager start
. Done.
sudo ifconfig eth0 up
and turn it on again withsudo ifconfig eth0 down
. Does this help?