CentOS7 安装后用命令行配置连网
1. 查看当前IP地址信息
# ip addr show
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: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:1a:4d:63:1c:23 brd ff:ff:ff:ff:ff:ff
inet xxx.xxx.xxx.xxx/xx brd xxx.xxx.xxx.xxx scope global enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::21a:4dff:fe63:1c23/64 scope link
valid_lft forever preferred_lft forever
在这个例子中,enp0s8 应该就是需要配置的网卡。
2. 编辑网卡配置
先进入 /etc/sysconfig/network-scripts/ 目录:
# cd /etc/sysconfig/network-scripts/
# ls
ifcfg-enp0s8 ifdown-ppp ifup-ib ifup-Team
ifcfg-lo ifdown-routes ifup-ippp ifup-TeamPort
ifdown ifdown-sit ifup-ipv6 ifup-tunnel
... ...
编辑 ifcfg-enp0s8 文件:
# vi ifcfg-enp0s8
编辑内容如下,充上缺少项,IP地址信息需要根据自己的网络设置调整:
ONBOOT = yes
IPADDR = 192.168.10.128
GATEWAY = 192.168.10.2
DNS1 = 192.168.10.2
DNS2 = 192.168.10.2
实践证明, DNS1 和 DNS2 也可以不加。
编辑后保存。
3. 重启网络服务
# service network restart
实践证明,重启系统也可以。
4. 测试连网
# ping www.baidu.com
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=54 time=27.0 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=54 time=21.3 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=3 ttl=54 time=15.8 ms
...
连网成功,OK!
来源:优快云
原文:https://blog.youkuaiyun.com/iw1210/article/details/80829589
版权声明:本文为博主原创文章,转载请附上博文链接!