Liunx跨网段通信

[root@localhost ~]# ip addr show      查看mac IP地址

[root@localhost ~]# ip a

[root@localhost ~]# ping 192.168.147.128
PING 192.168.147.128 (192.168.147.128) 56(84) bytes of data.
64 bytes from 192.168.147.128: icmp_seq=1 ttl=64 time=0.068 ms

ttl time to live(生存时间) 跳数

[root@localhost ~]# route -n    #查看路由类型
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.147.2   0.0.0.0         UG    100    0        0 ens33
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
192.168.147.0   0.0.0.0         255.255.255.0   U     0      0        0 ens33
192.168.147.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

[root@localhost ~]# arp -n    #显示本地ARP缓存中的条码
Address                  HWtype  HWaddress           Flags Mask            Iface
10.10.10.10              ether   00:0c:29:35:d8:75   C                     ens33
192.168.147.2            ether   00:50:56:e0:9f:61   C                     ens33
192.168.147.254          ether   00:50:56:e2:7b:4e   C                     ens33
192.168.147.1            ether   00:50:56:c0:00:08   C                     ens33

[root@localhost ~]# ethtool ens33  #显示网络接口相关信息

[root@localhost ~]# arping 192.168.147.128    #获取对方的mac地址

跨网段通信

关闭NetworkManager

[root@localhost ~]# systemctl stop NetworkManager

方式一:

网关:开启转发(临时)

[root@localhost ~]# echo 1 > /proc/sys/net/ipv4/ip_forward

[root@localhost ~]# cat /proc/sys/net/ipv4/ip_forward

A主机的默认网关 指向 192.168.147.222

[root@localhost ~]# route del default gw 192.168.147.2

[root@localhost ~]# route add default gw 192.168.147.222

B主机的默认网关 指向10.10.10.222

[root@localhost ~]# route del default gw 10.10.10.2

[root@localhost ~]# route del default gw 10.10.10.222

方法二:静态路由

主机1:192.168.147.128

[root@localhost ~]# route add -net 10.10.10.0 netmask 255.255.255.0 dev ens33

删除

[root@localhost ~]# route del -net 10.10.10.0 netmask 255.255.255.0 dev ens33

主机2:10.10.10.10

[root@localhost roobit]# route add -net 192.168.147.0 netmask 255.255.255.0 dev ens33

删除

[root@localhost roobit]# route del -net 192.168.147.0 netmask 255.255.255.0 dev ens33

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值