在这里插入代码片
大渣好我是渣渣辉今天我来介绍如何配置一个网卡会话
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.253.2 0.0.0.0 UG 100 0 0 ens160
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.253.0 0.0.0.0 255.255.255.0 U 100 0 0 ens160
先查出主机的 网关
cat /etc/resolv.conf
#
nameserver 192.168.253.2
[root@wzs network-scripts]#
查看主机的dns
nmcli connection add type ethernet ifname ens160 con-name static autoconnect yes
然后选择网卡 和 命名 然后 自动链接
```bash
nmcli connection modify static ipv4.addresses 192.168.253.123/24 ipv4.dns 192.168.253.2 ipv4.gateway 192.168.253.2 ipv4.method manual
然后通过第一步看到的网关和dns来配置 网关 dns 以及 配置ip地址和指定网卡使用配置文件里面的Ip地址不再先DHCP索取IP地址
然后我们链接到这个会话
nmcli connection up static
``
最后我们 ping 一下百度来看看我们成功没有
ping -c 2 www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=15.4 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=16.5 ms
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 48ms
rtt min/avg/max/mdev = 15.379/15.960/16.542/0.595 ms