Set IP
$ Sudo VI/etc/Network/interfaces
Autolo
Iface lo Inet loopback
Add the following content
Autoeth0
Iface eth0inet static
Address192.168.0.221 <-enter the IP address that is not used for self-check.
Netmask00000000255.0
Gateway192.168.0.1 <-enter the same gateway as the host
Save and disable gedit.
In this way, the IP address does not take effect immediately. Need to execute
$ Sudo/etc/init. d/networking restart
At this time, you can ping the computer in the LAN. But cannot access the Internet because DNS is not set.
The DNS information is saved in/etc/resolv. conf. Once changed, it takes effect immediately.
$ Sudo VI/etc/resolv. conf
Name server192.168.1.1
Name server8.8.8.8
Save and close, and now you can access the Internet.
However, after ubuntu12.04 is restarted, The nameserver set in/etc/resolv. conf will be cleared.
If you want to define a nameserver as always valid, there are two methods:
A is added to the NIC configuration file:
Iface eth0inet static
Address192.168.3.3
Netmask00000000255.0
Gateway192.168.3.1
Dns-nameservers114.114.114.1148.8.8.8
B. modify the configuration file of the resolvconf service:/etc/resolvconf/resolv. conf. d/base
Clear the original content and write the following content
Name server8.8.8.8
In this way, you can ensure that the configuration will be written to/etc/resolv. conf when the machine or resolvconf service is restarted.
In fact, there are always prompts in/etc/resolv. conf, but I did not pay attention to them:
DONOTEDITTHISFILEBYHAND--YOURCHANGESWILLBEOVERWRITTEN"
Attached Nic settings commands:
View Nic information: ifconfig
Set a nic ip Address: ifconfig eth0192.168.1.10netmask1_255.255.0
Restart the NIC to make the settings take effect: sudo/etc/init. d/networking restart
Change MAC address: ifconfig eth0hwetherxx: XX: xx
View route information: route-n
Add Gateway
Sudorouteadddefaultgw192.168.10.1
Delete Gateway
Sudoroutedeldefault
DNS server settings (UBUNTU)
1. Two free and easy-to-use DNS servers
Googledns: 8.8.8.8; 8.8.8.4
Opendns: 208.67.220.220; 208.67.222.222
2. view the local DNS Server
View dnsserver: nslookupwww.baidu.com
Update DNS settings, sudoresolvconf-u
Temporarily set ubuntustaticip and be able to access the Internet
1. ipnetmask
Sudoifconfig eth0192.168.0.167netmask1_255.0
2. DNS
Sudovi/etc/resolv. conf
Add
Nameserver8.8.8.8
3. Gateway
Sudorouteadddefalutgw192.168.10.1
Sudoroutedeldefault
Set static IP