environment:
1. Centos just installed the system
2. The virtual machine uses VirtualBox, and the network segment of the virtual machine network card (VirtualBox Host-Only Network) is: 192.168.0.*
============Scenario 1: The virtual machine is on the external network and does not communicate with the host =======================
1. Configure Internet access mode: (Network Address Translation) NAT
2. Configure dynamic IP acquisition and modify network configuration:
vim /etc/sysconfig/network-scripts/ifcfg-eth0
The modifications are as follows:
ONBOOT=yes, indicating that the network card is started at boot, save and exit
Restart the network card: service network restart, complete the configuration
============Scenario 2: The virtual machine communicates with the host (ie local area network) ======================
1. Configure the Internet access mode: Host-Only|bridge mode, the difference between the two: the former virtual machine cannot access the Internet, the latter can
2. Configure static IP and modify network configuration:
vim /etc/sysconfig/network-scripts/ifcfg-eth0, modified as follows:
ONBOOT=yes, indicating that this network card is started at boot
BOOTPROTO=static, obtain IP address statically
IPADDR=192.168.0.211, IP address
NETMASK=255.255.255.0, subnet mask
3. Modify the gateway to facilitate the virtual machine to access the Internet in bridge mode
vi /etc/sysconfig/network, modify the content as follows:
HOSTNAME=centos211, hostname
GATEWAY=192.168.0.1, gateway address
4. Modify DNS to facilitate ping the domain name
vi /etc/resolv.conf, empty the file and fill in only the following:
nameserver 192.168.0.1, use the gateway address for domain name resolution
nameserver 8.8.8.8, Google's DNS server
5. Modify hosts to facilitate ping the host name
vi /etc/hosts, add configuration
192.168.0.201 centos211
=============场景3:场景2切换到场景1======================
备注:即动静态IP互相切换,网络模式相互切换
举例:静->动
1、vi /etc/sysconfig/network-scripts/ifcfg-eth0,修改BOOTPROTO=dhcp
2、vi /etc/sysconfig/network,删除网关行(GATEWAY=192.168.0.1)
3、重启网卡:service network restart
=============配置项目,名词解释======================
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #网卡对应的设备别名
BOOTPROTO=static #网卡获得ip地址的方式(默认为dhcp,表示自动获取)
HWADDR=00:07:E9:05:E8:B4 #网卡MAC地址(物理地址)
IPADDR=192.168.100.100 #IP地址
NETMASK=255.255.255.0 #子网掩码
ONBOOT=yes #系统启动时是否激活此设备
# vi /etc/sysconfig/network
NETWORKING=yes #表示系统是否使用网络,no表示不能使用网络
HOSTNAME=centos211 #设置本机的主机名,要和/etc/hosts中设置的主机名相同
GATEWAY=192.168.0.1 #设置网关的IP地址
# vi /etc/resolv.conf
nameserver 8.8.8.8 #google域名服务器
nameserver 114.144.114.114 #国内域名服务器