CentOS 7中网络设置图文详解(2)

ping [主机名]/[IP地址]

[root@http01 ~]# ping 192.168.100.10 //测试网络通讯 PING 192.168.100.10 (192.168.100.10) 56(84) bytes of data. 64 bytes from 192.168.100.10: icmp_seq=1 ttl=128 time=0.860 ms 64 bytes from 192.168.100.10: icmp_seq=2 ttl=128 time=0.530 ms 64 bytes from 192.168.100.10: icmp_seq=3 ttl=128 time=0.514 ms 64 bytes from 192.168.100.10: icmp_seq=4 ttl=128 time=0.465 ms 跟踪数据包

测试从当前主机到目的主机之间经过的网络节点

traceroute命令

traceroute 目标主机地址

[root@http01 ~]# traceroute 192.168.100.10 traceroute to 192.168.100.10 (192.168.100.10), 30 hops max, 60 byte packets 1 gateway (192.168.144.2) 0.320 ms 0.255 ms 0.223 ms 2 * * * 3 * * * 4 * * * 域名解析

测试DNS域名解析

nslookup命令

nslookup [目标主机地址]/[目标DNS地址]

[root@http01 ~]# nslookup Server: 192.168.144.2 Address: 192.168.144.2#53 Non-authoritative answer: canonical name = Name: Address: 183.232.231.172 Name: Address: 183.232.231.174 设置网络参数的方式 临时配置——使用命令调整网络参数

简单、快速,可直接修改运行中的网络参数

一般只适合在调试网络的过程中使用

重新启动以后,所做的修改将会失效

固定设置——通过配置文件修改网络参数

修改各项网络参数的配置文件

适合对服务器设置固定参数时使用

需要重载网络服务或者重启以后才会生效

设置网络接口的参数

临时设置网络接口的IP地址、子网掩码

ifconfig 接口名 IP地址 [netmask(子网掩码)]

[root@http01 ~]# ifconfig ens33 //查看ens33接口IP地址 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 42 bytes 3966 (3.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 86 bytes 9346 (9.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@http01 ~]# ifconfig ens33 192.168.144.138/24 //设置临时IP地址 [root@http01 ~]# ifconfig ens33 //查看是否成功设置 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.138 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 2660 bytes 3613441 (3.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 844 bytes 57384 (56.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@http01 ~]# systemctl restart network //重启网络服务 [root@http01 ~]# ifconfig ens33 //查看IP地址 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) //设置的IP地址失效 RX packets 2708 bytes 3618185 (3.4 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 894 bytes 63590 (62.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

设置固定网络接口的IP地址、子网掩码

设置固定的网络接口IP地址、子网掩码,需要在网络接口的配置文件中更改配置文件来完成。

网络接口配置文件

/etc/sysconfig/network-scripts/

重启network网络服务

systemctl restart network

[root@http01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 //进入编辑网卡配置文件 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=staticl //将DHCP更改为staticl DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=2ef6b862-5201-48c5-a450-23b3720ab3a0 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.144.138 //输入要设定的IP地址 NETMAS=255.255.255.0 //输入子网掩码 GATEWAY=192.168.144.1 //输入网关地址 [root@http01 ~]# systemctl restart network //重启网络服务 [root@http01 ~]# ifconfig ens33 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.138 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::20c:29ff:fe5b:d3a0 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) //地址设置成功 RX packets 3832 bytes 3715216 (3.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1558 bytes 160876 (157.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

禁用或者重新激活网卡

禁用网卡

ifconfig 网络接口 down

重新激活网卡
ifconfig 网络接口 up

[root@localhost ~]# ifconfig ens33 down //禁用网卡 [root@localhost ~]# ifconfig ens33 //查看网卡信息,无IP地址连接 ens33: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 459 bytes 495831 (484.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 240 bytes 22865 (22.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~]# ifconfig ens33 up //重新激活网卡 [root@localhost ~]# ifconfig ens33 //查看网卡信息,成功获取IP地址 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 463 bytes 496409 (484.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 264 bytes 26630 (26.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

虚拟网络接口

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/11658.html