After installing the Linux system, log in and modify the file:
The code is as follows |
Copy Code |
# cat/etc/sysconfig/network-scripts/ifcfg-eth0 device= "Eth0″ bootproto=" None " hwaddr=" 00:50:56:be : 7a:d8″ ipaddr=192.168.2.108 #IP地址, you must set the gateway= 192.168.2.21 #网关地址, this is very important, if you do not set this on the smart is the LAN can not be connected with the external network of the onboot= "yes" #开机启动设置为yes uuid= "Fe45f058-9ce7-42a4-823c-abe472aad9f2″ Ipv6init=no netmask= 255.255.255.0 # Subnet mask |
After setting up, edit the domain name server settings file
The code is as follows |
Copy Code |
# cat/etc/resolv.conf NameServer 192.168.2.01 #域名服务器的地址, if you do not set this, you cannot access the site as a domain name Search hostname #这个相当于你本机的域名 |
Reboot the network service after setting
The code is as follows |
Copy Code |
#/etc/init.d/network Restart |
By doing the following Ifconfig command, you can see that your computer is already networked, and you can use the ping command to test whether it is networked.
Friendly tips:
Directly modify/etc/resolv.conf This file is useless, network service restart will be based on/etc/sysconfig/network-scripts/ifcfg-eth0 to overload the configuration, if Ifcfg-eth0 does not configure DNS, Then the resolv.conf will be flushed out and become null again.
What do we do? Here are two ways to fix this:
1, through the Ifcfg-eth0 can also set the DNS server address, and automatically modify or generate resolv.conf files.
2, in the Ifcfg-eth0 can be Peerdns parameters to determine whether to modify the resolv.conf file, set Peerdns=yes (which is also the system's default configuration) when the network device is enabled, the resolv.conf file will be modified or generated, Set Peerdns=no, do not make any changes to resolv.conf.
Supplemental Parts:
When a domain name resolution is required (for example, Ping www.111cn.net), the resolv.conf file is read first to obtain the DNS server address, and then the DNS server is sent a domain resolution request. If the resolv.conf is set incorrectly or no resolv.conf will cause domain name resolution to fail.
If the IFCFG-ETH0 is configured as DHCP mode, the system defaults to Peerdns=no, that is, the DNS address that will be obtained with DHCP to modify or generate resolv.conf files.
I think there is no special situation, do not set DNS in the resolv.conf, you should set the DNS server address in Ifcfg-eth0 convenient, that is, in line with normal thinking is easier to maintain and manage.
Note: the way to set up the network is limited to the Linux system such as Fedora,redhat,centos, and other systems may be somewhat different.