centos6.5 configure static IP ----- summary of painful learning experience

This study is based on the centos6.5 version of the Linux system.

       The configuration of static IP in centos6.5 depends on the mode in which it is configured. There are three modes in total: bridge mode, host mode, and nat mode (network address translation mode). You must understand the three modes, otherwise it is difficult to figure out how to configure static IP. 

Host mode : The real environment and the virtual environment are isolated; in this mode, all virtual systems can communicate with each other, but the virtual system and the real network are isolated. (The virtual system and the host machine system can communicate with each other, which is equivalent to the interconnection of the two machines through a twisted pair.) The only difference from nat is that in this method, there is no address translation service, so by default, the virtual machine can only access to the host. -------The host can be pinged, but cannot access the Internet;

Bridge mode : The host is virtualized by VMware and is the same as the physical host, which is equivalent to two hosts in the same LAN. When configuring static IP, use the same mask and gateway as the same IP address segment as the physical host. The physical host is the underlying computer system, usually Windows. In the bridging mode, the operating system virtualized by VMWare is like an independent host in the LAN (the host and the virtual machine are in a peer position), and it can access any machine on the network. We often need to configure the IP address, subnet mask, etc. for the virtual host (note that the IP address of the virtual host must be on the same network segment as the host IP address). In this way, the virtual machine can communicate independently with the host (of course, it can communicate with the virtual machine as long as it is in the same local area network). At the same time, after configuring the gateway and DNS addresses, it can access the Internet through the gateway or router of the local area network. Bridge mode does not have a virtual network card, which is different from the other two modes. . ------It can be pinged with the host host and can access the Internet;

NAT mode (network address translation mode): It is to let the virtual system use the NAT (network address translation) function to access the public network through the network where the host machine is located. Using NAT mode can realize accessing the Internet in the virtual system. To put it simply, the host machine builds a local area network, and then there is only one machine in the local area network, which is the virtual machine. The TCP/IP configuration information of the virtual system in NAT mode is provided by the DHCP server of the VMnet8 (NAT) virtual network and cannot be manually modified, so the virtual system cannot communicate with other real hosts in the local area network. The biggest advantage of using the NAT mode is that it is very simple for the virtual system to access the Internet. You only need the host machine to access the Internet. You do not need to configure the IP address, subnet mask, and gateway, but the DNS address still needs to be filled in according to the actual situation. --------The host computer cannot be pinged, but can access the Internet;
nat mode can access the Internet but cannot communicate with the host computer, which is safer in theory, and no matter what damage the virtual system does, it will not affect the host computer. The bridge mode is equivalent to connecting an independent host to the switch, which is generally used to provide services in the subnet.

This study mainly summarizes how to configure static IP in bridge mode

1. Confirm that the network adapter of the virtual machine is in bridging mode, and the bridging mode is the same as VWare's bridging mode, which is generally the default "automatic". This step can be ignored if it has not been modified before.

Second, configure the three files respectively

      1. Configure /etc/sysconfig/network-scripts/ifcfg-eth0   

     To check the IP and gateway of the machine in advance 

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

DEVICE=eth0    #虚拟机网卡名字
HWADDR=00:0c:29:cf:c0:4d  #mac地址
TYPE=Ethernet
UUID=5165aeb6-3c15-4fac-be7f-8262c73ee407
ONBOOT=yes      #开机启用网络配置
NM_CONTROLLED=yes
BOOTPROTO=static #使用静态IP
IPADDR=192.168.43.100  #自己设置的和物理主机一样网段的IP
GATEWAY=192.168.43.1   #和物理主机一样 的网关
NETMASK=255.255.255.0  #和物理主机一样的掩码
DNS1=8.8.8.8           #使用谷歌免费的域名解析服务器
IPV6INIT=no
USERCTL=no

 2. Configure /etc/sysconfig/network:

NETWORKING=yes
HOSTNAME=localhost.localdemain
GATEWAY=192.168.43.1   #网关地址,同物理主机的网关地址

3. Configure /etc/resolv.conf

nameserver 8.8.8.8

4. Restart the network card

 service network restart

3. Verification

  ping www.baidu.com

 As shown in the figure, it can be successful. Although there is packet loss, it means that the external network can be connected.

Guess you like

Origin blog.csdn.net/weixin_45813351/article/details/119880219