# Operating System: Ubuntu13.04
#
# Author: Sunny
# Article address: http://blog.csdn.net/sunnypotter/article/details/22598201
# Set static IP addresses:
#
# Preparation:
#1. view the network card, IP address, and subnet mask netmask in use. My name is eth0.
Ifconfig
Eth0 Link encap: Ethernet HWaddr ec: 9a: 74: 36: c8: 8c
Inet addr: 192.168.1.100 Bcast: 192.168.1.255 Mask: 255.255.255.0
# IP: 192.168.1.100, netmask: 255.255.255.0
#2. View gateway
Route-n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
# Gateway: 192.168.1.1
# Dns: 192.168.1.1 # generally, it works with gateways. Of course, you can also set other dns
#3. Set static IP now
Sudo vim/etc/network/interfaces
*********
# Interfaces (5) file used by ifup (8) and ifdown (8)
Auto lo
Iface lo inet loopback
# Set Static IP
Auto eth0 # My network card
Iface eth0 inet static # static, relative to dynamic (dhcp, that is, iface eth0 inet dhcp)
Address 192.168.1.100 # You can set available ip addresses in the same network segment, for example, 192.168.1.102
Gateway 192.168.1.1 # gateway
Netmask 255.255.255.0 # Subnet Mask
Dns-nameservers 192.168.1.1 # You can set multiple dns addresses or do not set them here. edit/etc/resolv. conf
Dns-nameservers 114.114.114.114
#4. Restart the NIC
Sudo service networking restart
# Or sudo/etc/init. d/networking restart
# If the problem persists, restart reboot.
# Note:
# When dns-nameservers is not set, manually add it in/etc/resolv. conf
Sudo vim/etc/resolv. cof
Nameserver 192.168.1.1
# In addition:
In earlier versions, you need to set resolv under/etc. conf file, and add nameserver to connect to the Internet. Otherwise, you can only access it through ip addresses and cannot parse the URL. (nslookup can view the ip address of the website. Of course, you must first have dns ).
This method is no longer recommended after Ubuntu12.04, because no matter what value you want to set in the configuration file, it will be restored to the initial state after restart. (Of course, it does not include the automatic setting of the boot script)
We recommend that you directly add the dns-nameservers <gateway ip> line to the interfaces configuration file.