centos8 中 如何配置静态IP
001、 以centos8.4为例
[root@localhost test01]# cat /etc/redhat-release ## 查看系统centos8.4 CentOS Linux release 8.4.2105
002、查看网络接口名称(网卡名称)
[root@localhost test01]# nmcli d ## 查看网络接口名称 DEVICE TYPE STATE CONNECTION ens160 ethernet connected ens160 virbr0 bridge connected (externally) virbr0 lo loopback unmanaged -- virbr0-nic tun unmanaged --
003、进入网卡配置文件所在的目录
[root@localhost test01]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# ls ifcfg-ens160
004、修改网卡配置文件
[root@localhost network-scripts]# vim ifcfg-ens160 PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static ## 此处由dhcp改为static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no NAME=ens160 UUID=024ee419-b660-4150-94f3-67fffb1ae8a2 DEVICE=ens160 ONBOOT=yes ## 改为yes,开机自启 IPADDR=192.168.174.130 ## 设置IP NETMASK=255.255.255.0 ## 设置子网掩码 GATEWAY=192.168.174.2 ## 设置网关 DNS1=119.29.29.29 ## DNS服务器1 DNS2=114.114.114.114 ## DNS服务器2 ~ ~ ~ ~ ~ :wq!
005、重启网络服务
[root@localhost network-scripts]# nmcli connection reload ## 重新加载网卡(centos7中激活网卡命令systemctl restart network不起作用) [root@localhost network-scripts]# nmcli connection up ens160 ## 激活网卡 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
006、查看IP是否生效
[root@localhost network-scripts]# ifconfig | head -n 3 ## 查看当前IP ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.174.130 netmask 255.255.255.0 broadcast 192.168.174.255 inet6 fe80::20c:29ff:fe9b:1211 prefixlen 64 scopeid 0x20<link> [root@localhost network-scripts]# ping -c 3 www.baidu.com ## 测试网络连通性 PING www.a.shifen.com (110.242.68.4) 56(84) bytes of data. 64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=1 ttl=128 time=11.7 ms 64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=2 ttl=128 time=11.4 ms 64 bytes from 110.242.68.4 (110.242.68.4): icmp_seq=3 ttl=128 time=12.3 ms --- www.a.shifen.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 11.417/11.792/12.281/0.382 ms
。
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2023-04-04 R语言中绘图,将图例设置在绘图区域之外
2022-04-04 ubuntu中 putty连接出现 network error. connection refused
2022-04-04 ubuntu中安装gcc c++编译器
2022-04-04 Peer reports incompatible or unsupported protocol version.
2022-04-04 cache.h:40:18: fatal error: zlib.h: No such file or directory
2022-04-04 bash: git: command not found...
2022-04-04 linux 中实现每两列数据合并为一列数据