设置静态IP
# 1- 查看本机ipconfig
ip:192.168.0.115
子网掩码:255.255.255.0
gateway:192.168.0.1
# 2- 修改网络配置文件:
vi /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO=static
IPADDR=192.168.0.111(因为要桥接,所以要设置与本机ip同网段)
NETMASK=255.255.255.0
GATEWAY=192.168.0.1(同上)
DNS1=8.8.8.8
# 3- 虚拟机网络连接改成桥接模式
# 4- 需要配置转发,否则会报错WARNING: IPv4 forwarding is disabled. Networking will not work.
vim /etc/sysctl.conf
net.ipv4.ip_forward=1
# 5- 重启网络服务,让配置生效
systemctl restart network
# 6- 查看是否成功,如果返回为“net.ipv4.ip_forward = 1”则表示成功
sysctl net.ipv4.ip_forward
# 7- 查看是否可ping通
ping 192.168.0.111 -c 2
ping www.baidu.com -c 2