配置环境
MacOS Monterey 12.0.1
虚拟机:CentOS 7
VMware 12.1.0
问题描述
Linux 虚拟机静态IP 无法连接外网
问题解决
- 网络适配器选择 NAT模式
- 并设置与我的Mac共享
- 查看本机Mac 的网络信息
终端输入->ifconfig
#结果显示
inet XXX.168.194.1 netmask 0xffffff00 broadcast XXX.168.194.255
- 修改Linux的网络信息
[root@master software]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO="static" #改成静态static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=2983b73e-5fc0-4e5c-a308-4a44a905adb1
DEVICE=ens33
ONBOOT=yes #修改成yes
IPADDR=XXX.168.194.151 #修改与Mac网段相同
NETMASK=255.255.255.0 #修改与Mac相同
GATEWAY=XXX.168.194.1 #修改成Mac的IP地址
DNS1=114.114.114.114 #修改DNS
PREFIX=24
~
~
~
"/etc/sysconfig/network-scripts/ifcfg-ens33" 20L, 382C
- 保存并退出,然后重启网络服务
service network restart
- 测试网络 Ping下百度,查看返回信息
[root@master software]# ping www.baidu.com
PING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=1 ttl=54 time=15.5 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=2 ttl=54 time=52.6 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=3 ttl=54 time=18.8 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=4 ttl=54 time=19.3 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=5 ttl=54 time=18.5 ms
如遇无法解析域名,修改Linux DNS配置
- 编辑DNS配置
vim /etc/resolv.conf
- 插入如下
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 114.114.114.114