|
CentOS 7 设置网络IP地址
自动获得IP地址
1,CentOS 7自动获得一个IP地址
[root@aminglinux ~]# dhclient
2,查看网卡信息,会发现有一个ens33的网卡
[root@aminglinux ~]# ip addr
1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
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: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:15:d9:1a brd ff:ff:ff:ff:ff:ff
inet 192.168.188.129/24 brd 192.168.188.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::e3ea:d232:efe0:c71/64 scope link
valid_lft forever preferred_lft forever
手动设置网卡的IP地址
1,网卡的信息在/etc/sysconfig/network-scripts里面,你可以编辑下面的ifcfg-ens33的文件,来手动绑定IP地址
(红色的部分是需要修改和添加的内容),修改完成后。按下ESC键,再输入“:wq"并回车保存退出。
[root@aminglinux ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
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=a69273cd-4aab-4cb7-8a24-8a100dd6c011
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.188.129
NETMASK=255.255.255.0
GATEWAY=192.168.188.2
DNS1=119.29.29.29
2,重启系统的网络服务,再查看下IP地址
[root@aminglinux ~]# systemctl restart network.service
[root@aminglinux ~]# ip addr
1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
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: ens33: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:15:d9:1a brd ff:ff:ff:ff:ff:ff
inet 192.168.188.129/24 brd 192.168.188.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::e3ea:d232:efe0:c71/64 scope link
valid_lft forever preferred_lft forever
3,最后测试下网络的连通性。
[root@aminglinux ~]# ping -c 4
www.aminglinux.com
PING
www.aminglinux.com
(182.254.152.182) 56(84) bytes of data.
64 bytes from 182.254.152.182 (182.254.152.182): icmp_seq=1 ttl=128 time=13.3 ms
64 bytes from 182.254.152.182 (182.254.152.182): icmp_seq=2 ttl=128 time=12.9 ms
64 bytes from 182.254.152.182 (182.254.152.182): icmp_seq=3 ttl=128 time=13.7 ms
64 bytes from 182.254.152.182 (182.254.152.182): icmp_seq=4 ttl=128 time=12.8 ms
---
www.aminglinux.com
ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 7410ms
rtt min/avg/max/mdev = 12.843/13.228/13.778/0.376 ms
|
|
|
|
|
|
|