centos默认安装好之后一般是自动分配本地ip,局域网外电脑是无法找到的。一般我们要设置静态IP。
1. 先查看默认ip
[root@localhost bin]# cd /etc/sysconfig/network-scripts[root@localhost network-scripts]# lsifcfg-eno16777736 ifdown-ppp ifup-ib ifup-Teamifcfg-lo ifdown-routes ifup-ippp ifup-TeamPortifdown ifdown-sit ifup-ipv6 ifup-tunnelifdown-bnep ifdown-Team ifup-isdn ifup-wirelessifdown-eth ifdown-TeamPort ifup-plip init.ipv6-globalifdown-ib ifdown-tunnel ifup-plusb network-functionsifdown-ippp ifup ifup-post network-functions-ipv6ifdown-ipv6 ifup-aliases ifup-pppifdown-isdn ifup-bnep ifup-routesifdown-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.255IPADDR=15.238.88.163NETMASK=255.255.255.0GATEWAY=15.238.88.252DNS1=15.238.81.207
2. 重启服务
service network restart
3. 修改虚拟机配置网络适配器,为桥接模式。