![没有获得 CentOS 7 的静态 IP](https://linux22.com/image/89784/%E6%B2%A1%E6%9C%89%E8%8E%B7%E5%BE%97%20CentOS%207%20%E7%9A%84%E9%9D%99%E6%80%81%20IP%20.png)
我不确定我的静态 IP 缺少什么?
这是我的网络配置文件:
/etc/hosts
:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.2 puppet master
192.168.1.3 agent1 machine1
192.168.1.4 agent2 machine2
192.168.1.5 agent3 machine3
/etc/sysconfig/network
:
# Created by anaconda
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=agent1
GATEWAY=192.168.1.1
主接口的配置文件/etc/sysconfig/network-scripts/ifcfg-enp0s3
:
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=9b49c161-f7b4-418d-ae5f-a4fae294d302
DEVICE=eth0
ONBOOT=no
IPADDR=192.168.1.3
PREFIX=32
GATEWAY=192.168.1.1
DNS1=192.168.1.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
这是输出ip addr
:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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 qlen 1000
link/ether 08:00:27:84:c2:b6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic enp0s3
valid_lft 85698sec preferred_lft 85698sec
inet6 fe80::a00:27ff:fe84:c2b6/64 scope link
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:18:f1:a8 brd ff:ff:ff:ff:ff:ff
inet 192.168.99.100/24 brd 192.168.99.255 scope global dynamic enp0s8
valid_lft 996sec preferred_lft 996sec
inet6 fe80::a00:27ff:fe18:f1a8/64 scope link
valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 00:00:00:00:00:00 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
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 500
link/ether 52:54:00:44:89:62 brd ff:ff:ff:ff:ff:ff
我已验证我已通过命令连接到互联网ping
。
这是目前最新的配置。
[root@agent1 ~]# cat /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
search netgear
nameserver 192.168.1.1
[root@agent1 ~]# ping -c 5 google.com
ping: unknown host google.com
[root@agent1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
[b]NAME=enp0s3[/b]
UUID=9b49c161-f7b4-418d-ae5f-a4fae294d302
[b]DEVICE=enp0s3[/b]
[b]ONBOOT=yes
NM_CONTROLLED=NO[/b]
IPADDR=192.168.1.3
PREFIX=32
GATEWAY=192.168.1.1
DNS1=192.168.1.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
[root@agent1 ~]# cat /etc/sysconfig/network
# Created by anaconda
NETWORKING=yes
NETWORKING_IPV6=no
GATEWAY=192.168.1.1
[root@agent1 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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 qlen 1000
link/ether 08:00:27:84:c2:b6 brd ff:ff:ff:ff:ff:ff
inet [b]192.168.1.3[/b]/32 brd 192.168.1.3 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe84:c2b6/64 scope link
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 08:00:27:18:f1:a8 brd ff:ff:ff:ff:ff:ff
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
link/ether 52:54:00:44:89:62 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
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
link/ether 52:54:00:44:89:62 brd ff:ff:ff:ff:ff:ff
[root@agent1 ~]#
请注意,这一切都在 Windows 10 上安装的 VirtualBox 上。我只有两个网络适配器适配器 1 桥接器和适配器 2 主机。
我希望这些信息可以帮助我们识别并解决问题。
答案1
将您的名称服务器resolve.conf
放入8.8.8.8
编辑你的/etc/sysconfig/network-scripts/ifcfg-enp0s3
ONBOOT=no
NAME=eth0
DEVICE=eth0
到下面
ONBOOT=yes
NAME=enp0s3
DEVICE=enp0s3
systemctl restart network.service