Centos7 After you configure a static IP can not ping outside the network or there are two IP issues

Scene: recently encountered a problem when connecting to virtual machines such as SecureCRT or Xshell tool, often after over a day or two suddenly Rom, then viewed directly by the virtual machine IP address is not found in the original IP settings the IP, the original setting my card is DHCP-assigned IP address, IP address is not fixed. So I reconnected through a new IP address, and finally even on, but a few days and Rom. This situation is more worried, after all, I can not always have it change IP. So I set a static IP address of the IP, but later encountered a new pit.

Note: The environment is based on Centos7

One problem: the situation after the emergence of the Internet can not set a static IP

Need to know before setting a static IP is access to the Internet, usually as long as the host can not turn over the Internet and configure the virtual machine, are all access to the Internet. Unless you are not a native image, but others turn you directly copied, the situation may not be directly ping the external network appears. But it is generally configuration issues.

1. Set a static IP

vim /etc/sysconfig/network-scripts/ifcfg-ens33

 

 

Assign IP through DHCP instead of static IP, that is,

The BOOTPROTO = dhcp instead BOOTPROTO = static

ONBOOT = yes show boot from the start

After setting a static IP on the need to specify the IP

IPADDR for the IP address

NETMASK the subnet mask

GATEWAY gateway, note the IP address of the gateway must be the virtual machines on the same network segment, otherwise no Internet access, after all, we have only one way to go, right,

DNS is the DNS slightly, just what DNS server can, you can also set up your own, be happy. But make sure you must have DNS service, and is working properly. General problems can not ping an external network are the DNS, DNS equivalent to navigation, navigation is a problem if it can only be lost.

Note: After setting the NIC card information need to restart the service

service network restart

Viewing IP Information

ifconfig or hostname -I, can be seen, the IP information is changed, and has been connected through the tool.

 

 

2. After the Internet can not set a static IP

After each change IP I finished there is such a situation. And the Internet are the same than a set, you can ping the gateway and the host and the same network of machines, but is not ping outside the network.

 

So I direct ping IP address of Baidu, you can ping. . .

 

 what is the problem? Network is through!

URL but different IP addresses through, is not that DNS problems yet

But I've set up a DNS

So continue pingDNS server

 

 Pass. . . But still outside the network of ping nowhere

Coupled with a DNS try

 

 

 

 They discovered the pass, what is the reason, the first to try a DNS deleted

 

 

 

 DNS DNS1 into the first try, the result still pass. OK.

Question two: two IP address appears after setting a static IP

BOOTPROTO check whether the static ,, if you still set to the default DHCP, the host will continue to assign IP addresses to you, and you set the same IP address to take effect, so there will be two IP addresses. If there is, then later it changed to static, in the back of the card configuration information plus NM_CONTROLLED = no

 

 

Then service network restart to restart the network, no.

 

Guess you like

Origin www.cnblogs.com/maohai-kdg/p/11445677.html