Linux网络基础中,常见的命令。ping命令、route命令、ip命令

ping命令

查看检测目标主机是否连接,这里注意有的防火墙/企业路由器为了安全考虑,开启防ping

  1. ping www.baidu.com

  2. ping 114.114.114.114

  3. ping baidu.com

企业案例

企业级如果上不了网,排查流程

  1. 步骤一
    检查硬件
    传输介质—网线用寻线仪排查或交叉法排查,查看网线
    物理设备,看网卡灯亮不亮
  2. 步骤二
    检查数据链路
    C7 命令ip a
    C6 命令ipconfig 需yum install -y net-tools
    ping 网关地址
    192.168.1.1
    192.168.1.255
  3. 步骤三
    检查外网是否连通
    ping 公网的ip地址
    114.114.114.114
  4. 步骤四
    检查DNS服务器
    ping域名
    baidu.com
    www.baidu.com

route命令

yum install -y net-tools
查看系统中路由表信息

[root@xxx ~]# :route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.2        0.0.0.0         UG    100    0        0 ens33
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33

添加网段

[root@xxx ~]# :route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.2        0.0.0.0         UG    100    0        0 ens33
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33
[root@xxx ~]# :route add -net 192.168.0.0 netmask 255.255.255.0 dev ens33
You have new mail in /var/spool/mail/root
[root@xxx ~]# :route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.2        0.0.0.0         UG    100    0        0 ens33
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 ens33

添加网关

[root@xxx ~]# :route add -net 192.168.0.0/24 gw 192.168.0.1
You have new mail in /var/spool/mail/root
[root@xxx ~]# :route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.2        0.0.0.0         UG    100    0        0 ens33
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.0.0     192.168.0.1     255.255.255.0   UG    0      0        0 ens33
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 ens33

删除网关/路由条目

[root@xxx ~]# :route del -net 192.168.0.0/24 gw 192.168.0.1
[root@xxx ~]# :route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.2        0.0.0.0         UG    100    0        0 ens33
10.0.0.0        0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 ens33

ip命令

可选项

[root@xxx ~]# :ip r
default via 10.0.0.2 dev ens33 proto static metric 100 
10.0.0.0/24 dev ens33 proto kernel scope link src 10.0.0.140 metric 100 
192.168.0.0/24 dev ens33 scope link 

添加网关

[root@xxx ~]# :ip route add 192.168.0.0/26 via 10.0.0.2
You have new mail in /var/spool/mail/root
[root@xxx ~]# :ip r
default via 10.0.0.2 dev ens33 proto static metric 100 
10.0.0.0/24 dev ens33 proto kernel scope link src 10.0.0.140 metric 100 
192.168.0.0/26 via 10.0.0.2 dev ens33 
192.168.0.0/24 dev ens33 scope link 

发布了51 篇原创文章 · 获赞 5 · 访问量 1087

猜你喜欢

转载自blog.csdn.net/weixin_46669463/article/details/105542122
今日推荐