How do I set a static IP address?
Solution 1
You don't really need to edit `/etc/network/interfaces' to set the static IP addresses. You can do that using the Network Manager. Just right click on the network applet and go to Edit Connections.
If you however don't want to use the network manager, the following steps will help you assign multiple ip addresses:
- Disable the network manager
sudo service network-manager stop
- Get the IP address from the server using:
sudo dhclient eth0
- Assign the first ip addresses like this:
sudo ip addr add 192.168.20.222/24 dev eth0
, and repeat for other IP addresses. - Add the default route using:
sudo route add default gw <internet gateway ip address>
If you do step 2, step 4 is not required. Hope that helps.
Solution 2
If the problem persists while setting up a static ip, use the following steps to set up a new static ip address:
Open terminal (command line) and type the following command:
sudo vi /etc/network/interfaces
OR
sudo gedit /etc/network/interfaces
Make the changes as follows:
auto eth0
iface eth0 inet static
address 10.10.29.66
netmask 255.255.255.192
network 10.10.29.65
broadcast 10.10.29.127
gateway 10.10.29.65
Save and close the file. Restart networking:
sudo /etc/init.d/networking restart
Solution 3
If you have NetworkManager installed, it could be causing a problem with /etc/network/interfaces. See /usr/share/doc/network-manager/README.Debian (I've used Ubuntu just enough to install it for someone else).
Related videos on Youtube
iAsk
Updated on September 18, 2022Comments
-
iAsk over 1 year
My eth0 is using DHCP to get IP address for Internet. However I still need to set some static IP for my LAN. The following is my setting in /etc/network/interface. Any problem on the script ? I always failed when I try to start network.
I checked the IP via ifconfig. and found eth0:3 is set but others. May I know what's the problem?
1 auto lo 2 iface lo inet loopback 3 4 #auto eth0 5 #iface eth0 inet dhcp 6 7 auto eth0:1 8 iface eth0:1 inet static 9 address 192.168.20.222 10 netmask 255.255.255.0 11 gateway 192.168.20.1 12 13 auto eth0:2 14 iface eth0:2 inet static 15 address 192.168.30.222 16 netmask 255.255.255.0 17 gateway 192.168.30.1 18 19 auto eth0:3 20 iface eth0:3 inet static 21 address 192.168.211.222 22 netmask 255.255.255.0 23 gateway 192.168.221.1
-
Andrea Corbellini over 9 yearspossible duplicate of How to set static ip address in guest Ubuntu running in Virtual Box
-
-
iAsk about 12 yearscan network manager achieve some work? I tried to assign static IP in network manager and also failed.
-
iAsk about 12 yearsthanks. I prefer use Network-manager. but when I edit the connection and add two more static ip address and then reboot. Then the ip change to lan only, I lost my dhcp ip address.
-
Ben S Nadler about 12 yearsWell then go with the command line.
-
iAsk about 12 yearscommand line is easier, but I need to input password every time. thanks
-
Ben S Nadler about 12 years
sudo su
will relieve you of that trouble. -
iAsk about 12 yearssudo su still need input password, how come to relieve the trouble.
-
isomorphismes over 10 years@iAsk
sudo visudo
will solve that askubuntu.com/a/147265/12518