RHEL7、CentOS7命令添加和修改网卡IP地址和NDS
RHEL7、CentOS7默认安装之后是没有启动网络连接!(我们就不按6的方试设置IP了,用命令方试添加IP、网关和DNS)
一、设置IP地址、网关和DNS
#nmcli connection add type ethernet autoconnect yes con-name eht0 ifname eth0 ip4 192.168.99.2 gw4 192.168.99.1 #添加IP地址和网站 #nmcli connection modify eth0 ipv4.dns 8.8.8.8 #添加DNS #systemctl restart network #重新启动网络
#ip a #查看IP
[root@www ~]# ip a 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 18:66:da:eb:15:cc brd ff:ff:ff:ff:ff:ff inet 192.168.99.2/24 brd 192.168.99.255 scope global eth0 valid_lft forever preferred_lft forever
#ping -c4 www.baidu.com
二、修改IP地址、网关和DNS
# nmcli connection modify eth0 ipv4.addresses 192.168.0.11/24 # nmcli connection modify eth0 ipv4.method manual #nmcli connection modify eth0 ipv4.dns 9.9.9.9 #systemctl restart network
#ip a 也可通过 #nmcli show dev
[root@www ~]# ip a 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000 link/ether 18:66:da:eb:15:cc brd ff:ff:ff:ff:ff:ff inet 192.168.0.11/24 brd 192.168.0.255 scope global eth0 valid_lft forever preferred_lft forever
#man nmcli 可以通过查看网卡帮助文件有更详细的说明
至此:RHEL7、CentOS7添加网卡和修改网卡IP、DNS 已完成
原文地址:https://www.cnblogs.com/3daytears/p/10436430.html
时间: 2024-10-07 07:07:10