centos默认安装好之后一般是自动分配本地ip,局域网外电脑是无法找到的。一般我们要设置静态IP。
1. 先查看默认ip
[root@localhost bin]# cd /etc/sysconfig/network-scripts [root@localhost network-scripts]# ls ifcfg-eno16777736 ifdown-ppp ifup-ib ifup-Team ifcfg-lo ifdown-routes ifup-ippp ifup-TeamPort ifdown ifdown-sit ifup-ipv6 ifup-tunnel ifdown-bnep ifdown-Team ifup-isdn ifup-wireless ifdown-eth ifdown-TeamPort ifup-plip init.ipv6-global ifdown-ib ifdown-tunnel ifup-plusb network-functions ifdown-ippp ifup ifup-post network-functions-ipv6 ifdown-ipv6 ifup-aliases ifup-ppp ifdown-isdn ifup-bnep ifup-routes ifdown-post ifup-eth ifup-sit [root@localhost network-scripts]# gedit ifcfg-eno16777736
打开默认配置:
TYPE="Ethernet" BOOTPROTO="dhcp" DEFROUTE="yes" PEERDNS="yes" PEERROUTES="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_PEERDNS="yes" IPV6_PEERROUTES="yes" IPV6_FAILURE_FATAL="no" NAME="eno16777736" UUID="157c8fb5-23b3-414c-8519-25bef9b20a54" DEVICE="eno16777736" ONBOOT="yes"
以下是要修改的内容
TYPE="Ethernet" BOOTPROTO="static" DEFROUTE="yes" PEERDNS="yes" PEERROUTES="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_PEERDNS="yes" IPV6_PEERROUTES="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="ens33" UUID="8ee24af1-39b1-428d-83b0-13017df6f844" DEVICE="ens33" ONBOOT="yes" BROADCAST=15.238.88.255 IPADDR=15.238.88.163 NETMASK=255.255.255.0 GATEWAY=15.238.88.252 DNS1=15.238.81.207
2. 重启服务
service network restart
3. 修改虚拟机配置网络适配器,为桥接模式。