ubuntu sets the implementation of static IP

  • 2020-05-10 23:24:08
  • OfStack

Ubuntu setting static IP:

Switch to the root user and go to the /etc/network directory. Back up interfaces files (backing up files is a good habit)

Now edit the interfaces file and add the following statement:


1 # Assgin static IP by eric on 26-SEP-2012
2 iface eth0 inet static
3 address 192.168.196.135     #change to your static IP
4 netmask 255.255.255.0      #change to your netmask
5 gateway 192.168.196.255     #change to your getway
6 #We must specify dns-nameserver here
7 #in order to get internet access from host
8 dns-nameservers 192.168.196.255
9 auto eth0

The content of interfaces file after editing is as follows:


root@ubuntu:/etc/network# cat interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

#add by andy at 2014-08-14
# Assgin static IP by eric on 26-SEP-2012
iface eth0 inet static
address 192.168.196.135     #change to your static IP
netmask 255.255.255.0      #change to your netmask
gateway 192.168.196.255     #change to your getway
#We must specify dns-nameserver here
#in order to get internet access from host
dns-nameservers 192.168.196.255
auto eth0

The next step is to restart the network card:


root@ubuntu:/etc/network# /etc/init.d/networking restart
 After the restart is complete, test 1 Bottom: 

 root@ubuntu:/etc/network# ping www.baidu.com.cn
 PING www.a.shifen.com (220.181.112.244) 56(84) bytes of data.
 64 bytes from 220.181.112.244: icmp_req=1 ttl=128 time=6.12 ms
 64 bytes from 220.181.112.244: icmp_req=2 ttl=128 time=14.7 ms

OK. The static IP setup is complete.

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: