- 服务器版本 CentOS 7.5
- VirtualBox配置网络为桥接模式
- 物理机(宿主机)信息
ip:192.168.0.104
subnet mask:255.255.255.0
gateway:192.168.0.1
- 查看服务器ip信息
>ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:af:44:88 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.106/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::xxx:xxxx:xxxx:4488/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
服务器当前ip: 192.168.0.106, 网卡: enp0s3
- 修改配置文件
>vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE="Ethernet"
BOOTPROTO="static" #静态方式
NM_CONTROLLED="no" #不使用网络管理器
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="enp0s3"
UUID="2b4bcec5-6c11-411b-b7b5-177d6b1075b2"
DEVICE="enp0s3"
ONBOOT="yes"
IPADDR=192.168.0.110 #设置固定ip
NETMASK=255.255.255.0 #子网掩码为物理机子网掩码(subnet mask)
GATEWAY=192.168.0.1 #设置网关为物理机网关(gateway)
- 重启网卡
>service network restart
- 添加DNS服务器
>vim /etc/resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 114.114.114.114 #114DNS
nameserver 114.114.114.115
- 验证ip
>ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:af:44:88 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.110/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::xxx:xxxx:xxxx:4488/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
>ping www.baidu.com #可ping通
服务器当前ip: 192.168.0.110, 网卡: enp0s3
所有评论(0)