CentOS 7 设置网络IP地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7 设置网络IP地址相关的知识,希望对你有一定的参考价值。
CentOS 7 设置网络IP地址自动获得IP地址
1,CentOS 7自动获得一个IP地址
[[email protected] ~]# dhclient
2,查看网卡信息,会发现有一个ens33的网卡
[[email protected] ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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"并回车保存退出。
[[email protected] ~]# 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地址
[[email protected] ~]# systemctl restart network.service
[[email protected] ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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,最后测试下网络的连通性。
[[email protected] ~]# 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
以上是关于CentOS 7 设置网络IP地址的主要内容,如果未能解决你的问题,请参考以下文章