Description: In the online tutorial usually there will be such a misleading idea, according to the configuration file settings will not take effect, and even without a little effect, after the investigation found that Linux set IP this topic of the entry thread should be divided into two types: 1 for the Server version, 2 for Desktop Edition, the two versions of the way to set up a very big difference, mainly in the software problem. The service version can be set according to the regular version, but the desktop version has a Network-manager software, this software is to simplify the IP settings, so many times in accordance with the online configuration tutorial set up will not be effective after the problem; general if you follow the settings of the server edition , it is important that the Network-manager will expire after a reboot, rather than restarting the service. These settings are also valid for Ubuntu and CentOS 6.
Setup steps:
First, the server version:
Available for both Ubuntu and CentOS 6 configurations.
1. Modify the IP address
Open/etc/network/interfaces
sudo vim/etc/network/interfaces
Add the following statement:
Auto eth0 #要设置的网卡iface eth0 inet static #设置静态IP, if the use of automatic IP with DHCP, the following do not set, generally less use addressxxx.xxx.xxx.xxx # IP address netmaskxxx.xxx.xxx.xxx #子网掩码gatewayxxx. xxx.xxx.xxx #网关
2. Modify DNS
Open/etc/resolv.conf
sudo vim/etc/resolv.conf
Note: The above set of files will be overwritten after restart, if you want to persist, you need to modify:/etc/resolvconf/resolv.conf.d/base
Change to the following content:
172.16. 3.4 172.16. 3.3 #希望修改成的DNS
3. Restart the service to take effect
Run the first time, and then add this command to restart the network configuration in the rc.local:
sudo /etc/init.d/networking restart #使网卡配置生效 sudo /etc/init.d/resolvconf restart #使DNS生效
Second, desktop version:
Desktop has a Network-manager software, this software if it is set up, then the default will be the above configuration, Network-manager will expire, but this setting will only take effect if you restart the computer.
If you do not restart, then you need to stop the service to set
sudo service Network-manager stop
Next, you can configure it with the above configuration.
But this kind of practice is a bit troublesome, since using the desktop, it is better to use Network-manager to set up faster (that is, set the network settings inside).
Similarly, if you want to set the IP of the wireless network card, with this configuration is also the fastest, there is no need to use the above configuration to configure.
Three, command line quick settings:
This mode will fail when restarted.
1, the first stop Network-manager service
sudo service Network-manager stop
2. Set IP and subnet masks
sudo ifconfig 192.168. 199.31 255.255. 255.0
3. Setting up the Gateway
sudo 192.168. 199.1
4. Set up DNS
sudo su Echo " nameserver 192.168.199.1 " >>/etc/resolv.conf
When you are finished, enter exit and the above is only effective immediately. However, after a reboot, the first method is used in a persistent manner.
Iv. Summary:
The above methods are the most common way, there is no more in-depth approach, such as ARP, and so on, if you want to dig into this aspect of the method, the following is a reference tutorial.
Reference:
Https://wiki.debian.org/NetworkConfiguration (Official tutorial)
Https://www.cnblogs.com/sankye/p/5020721.html (the above content is inspired by this article)
Https://zhidao.baidu.com/question/2206476521318351508.html
http://blog.csdn.net/wangjingfei/article/details/5283632/
http://blog.csdn.net/aristolto/article/details/50543928
http://blog.csdn.net/zzu09huixu/article/details/17893357
http://blog.csdn.net/cuiyifang/article/details/8166977
Http://www.360doc.com/content/11/1202/12/6828497_169109083.shtml
Http://www.linuxidc.com/Linux/2014-06/102670.htm (ifconfig obsolete, with IP as an alternative)
Ubuntu 16.04 Set IP