如何在CentOS 7 Minimal上配置静态IP地址
在这个简短的教程中,我将解释如何在CentOS 7 Minimal上配置静态IP地址。
首先,需要编辑以太网的设置。让我们从编辑“/etc/sysconfig/network-scripts/ifcfg-enp0s3
”文件开始:
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
文件内容如下:
HWADDR=08:00:27:6C:FF:91
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPADDR=192.168.0.88
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s3
UUID=ea68db6e-461e-427d-b9a8-bfcf6e1a4fc6
ONBOOT=yes
保存并退出。
现在,配置默认网关:
vi /etc/sysconfig/network
并添加以下行:
NETWORKING=yes
HOSTNAME=centos7
GATEWAY=10.1.1.253
配置DNS服务器
vi /etc/resolv.conf
添加以下行:
nameserver 8.8.8.8
nameserver 8.8.4.4
现在重启你的网络或重启系统:
/etc/init.d/network restart
检查你的网络:
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:6c:ff:91 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.88/24 brd 192.168.0.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe6c:ff91/64 scope link
valid_lft forever preferred_lft forever