Linux基础知识学习——第四天:配置网络ip地址
一、ifconfig查看网络信息
[root@ORCL ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.198.142 netmask 255.255.255.0 broadcast 192.168.198.255
inet6 fe80::8fa3:84d5:c0be:76b5 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:12:4f:f3 txqueuelen 1000 (Ethernet)
RX packets 30748 bytes 2196457 (2.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 54570 bytes 71048735 (67.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 3344 bytes 236121 (230.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3344 bytes 236121 (230.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:f7:83:20 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
二、ping测试主机之间的网络
2.1 基本语法
//用来测试当前服务器是否可以连接目标主机
ping 目标主机
2.2 测试当前服务器是否可以连接宿主机
[root@ORCL ~]# ping 192.168.198.1
PING 192.168.198.1 (192.168.198.1) 56(84) bytes of data.
64 bytes from 192.168.198.1: icmp_seq=1 ttl=128 time=0.297 ms
64 bytes from 192.168.198.1: icmp_seq=2 ttl=128 time=0.317 ms
64 bytes from 192.168.198.1: icmp_seq=3 ttl=128 time=0.226 ms
可以ping通。
2.2 测试当前服务器是否可以连接百度
[root@ORCL ~]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.14) 56(84) bytes of data.
64 bytes from www.baidu.com (180.101.49.14): icmp_seq=1 ttl=128 time=10.5 ms
64 bytes from www.baidu.com (180.101.49.14): icmp_seq=2 ttl=128 time=11.1 ms
64 bytes from www.baidu.com (180.101.49.14): icmp_seq=3 ttl=128 time=10.6 ms
可以ping通。
三、修改IP地址为固定的
3.1 ifconfig查看一下网络信息
找到ifcfg-ens33文件,修改其内容。
3.2 修改IP配置文件
[root@ORCL ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
3.3 重启网络
[root@ORCL ~]# service network restart
Restarting network (via systemctl):
[ OK ]
四、修改IP地址后可能遇到的问题
(1)物理机器能ping通虚拟机,但是虚拟机ping不通物理机,一般都是因为物理机的防火墙问题,把物理机防火墙关闭就行.
(2)虚拟机能ping通物理机,但是虚拟机ping不通外网,一般都是因为DNS的设置有问题.
(3)虚拟机 ping www.baidu.com 显示域名未知等信息,一般查看GATEWAY和DNS设置是否正确.
(4)如果以上全部设置完还是不行,需要关闭NetworkManager服务.
关闭: systemctl stop NetworkManager
禁用: systemctl disable NetworkManager
(5)如果检查发现systemctl status network 有问题,需要检查ifcgf-ens33