Linux 上两个网络之间的路由

Linux 上两个网络之间的路由

我的系统拓扑:

在具有 2 个以太网端口(eth0、eth1)的 ubuntu 机器上,我已连接另一台 ubuntu 机器作为客户端和一个 OCRCamera(也是客户端)。

要求是主 ubuntu 机器将是 DHCP 服务器和路由器,这样 ubuntu 客户端和摄像头都将从主 ubuntu 机器获取 IP 地址。ubuntu 客户端和摄像头需要能够相互 ping/ssh。

使用 nmcli 命令和“/etc/dnsmasq.d/X”中的配置文件,我在主 ubuntu 机器上以共享模式配置了 eth0 和 eth1:

“/etc/dnsmasq.d/XXX”配置文件:

no-resolv
port=53
bogus-priv
strict-order
expand-hosts

domain=wombat.pixellot.com

# Set Listen address
listen-address=192.168.101.1
dhcp-range=set:group1,192.168.101.10,192.168.101.100,24h
dhcp-option=tag:group1,option:router,192.168.101.1
dhcp-option=tag:group1,option:dns-server,192.168.101.1
dhcp-option=tag:group1,option:netmask,255.255.255.0

listen-address=192.168.102.1
dhcp-range=set:group2,192.168.102.10,192.168.102.100,24h
dhcp-option=tag:group2,option:router,192.168.102.1
dhcp-option=tag:group2,option:dns-server,192.168.102.1
dhcp-option=tag:group2,option:netmask,255.255.255.0

nmcli 命令:

sudo nmcli connection add type ethernet ifname eth0 ipv4.method shared con-name EthCon0
sudo nmcli connection add type ethernet ifname eth1 ipv4.method shared con-name EthCon1

sudo nmcli connection modify EthCon0 ipv4.addresses 169.254.101.1/24
sudo nmcli connection modify EthCon1 ipv4.addresses 169.254.101.2/24

sudo nmcli connection up EthCon0
sudo nmcli connection up EthCon1

主 ubuntu 机器上的 ifconfig 如下所示:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.101.1  netmask 255.255.255.0  broadcast 192.168.101.255
        inet6 fe80::c706:5a57:f51d:a8b0  prefixlen 64  scopeid 0x20<link>
        ether 48:b0:2d:3b:6d:0b  txqueuelen 1000  (Ethernet)
        RX packets 76802  bytes 6700303 (6.7 MB)
        RX errors 0  dropped 8  overruns 0  frame 0
        TX packets 73153  bytes 7426646 (7.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 37  

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.102.1  netmask 255.255.255.0  broadcast 192.168.102.255
        inet6 fe80::cf74:51de:1317:fe42  prefixlen 64  scopeid 0x20<link>
        ether ae:aa:82:3c:08:6c  txqueuelen 1000  (Ethernet)
        RX packets 41  bytes 4289 (4.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 187  bytes 29743 (29.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ubuntu 客户端和分别连接到 eth0 和 eth1 的摄像头都获得了一个 ip 地址,并且可以 ping 通:

pixellot@wombat:~$ sudo ping 192.168.101.98
PING 192.168.101.98 (192.168.101.98) 56(84) bytes of data.
64 bytes from 192.168.101.98: icmp_seq=1 ttl=64 time=0.581 ms
64 bytes from 192.168.101.98: icmp_seq=2 ttl=64 time=0.569 ms

pixellot@wombat:~$ sudo ping 192.168.102.32
PING 192.168.102.32 (192.168.102.32) 56(84) bytes of data.
64 bytes from 192.168.102.32: icmp_seq=1 ttl=64 time=0.451 ms
64 bytes from 192.168.102.32: icmp_seq=2 ttl=64 time=0.508 ms

但是,当我尝试从 ubuntu 客户端 ping 到摄像头时,它不起作用:

yvesh@yvesh-XPS-15-9510:~$ ping 192.168.102.32
PING 192.168.102.32 (192.168.102.32) 56(84) bytes of data.
From 192.168.101.98 icmp_seq=1 Destination Host Unreachable
From 192.168.101.98 icmp_seq=2 Destination Host Unreachable

我怎样才能让两个客户端相互通信?有没有解决这个问题的路由解决方案?(不是 ssh 隧道)我尝试了很多方法,但我被困住了,无法进一步开发 :-( 请帮忙!<3

相关内容