首页 > 代码库 > CentOS设置静态IP并可访问外网
CentOS设置静态IP并可访问外网
1.设置虚拟机的网络适配器为NAT模式
2.编辑虚拟网络编辑器
选中VMNet8更改设置
子网IP:192.168.101.0
子网掩码:255.255.255.0
NAT设置
网关:192.168.101.2
DHCP设置
起始地址:192.168.101.128
结束地址:192.168.101.254
3.宿主机VMNet8更改适配器设置
IP地址:192.168.101.1
子网掩码:255.255.255.0
其它都不设
4.虚拟机静态IP设置
右键网络图标,Edit Connections, IPV4 Settings
Method:Manual
Address:192.168.101.128
NetMask:255.255.255.0
GateWay:192.168.101.2
DNS servers:192.168.101.2
Search domains:localdomain
5.测试外网访问
ping www.baidu.com
宿主机用XShell进行连接
配置结果查看:
-----------------------------------------------------------------
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO=none
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="aa8f2b19-fea9-4d05-a84c-fa419abc4537"
IPADDR=192.168.101.128
PREFIX=24
GATEWAY=192.168.101.2
DNS1=192.168.101.2
DOMAIN=localdomain
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME="System eth0"
HWADDR=00:0C:29:F2:17:46
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
LAST_CONNECT=1469458152
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
vi /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.101.2
-----------------------------------------------------------------
CentOS设置静态IP并可访问外网