Traffic between two Ethernet interfaces on Ubuntu host My Ubuntu 20.04 host has two interfaces and I want to send data between them. I have connected them together with any Ethernet cable, no matter cross or patch cord - all modern Ethernet adapters have internal crossing if needed. Desktop Ubuntu may warn about mis-configured network, I am going to config and start with optional step for setting desired speed+mode, e.g. 1 Gbit: sudo ethtool --change enp1s0 speed 1000 duplex full sudo ethtool --change enp2s0 speed 1000 duplex full I separate interfaces using network namespaces, so I add "ns1" for 1st interface while second will remain on the root: sudo ip netns add ns1 sudo ip link set enp1s0 netns ns1 enp1s0 becomes invisible from root. I assign IPs using independent sub-nets: sudo ip netns exec ns1 ip addr add 192.168.21.21/24 dev enp1s0 sudo ip addr add 192.168.22.22/24 dev enp2s0 If interfaces down, I turn them up: sudo ip netns exec ns1 ip link set dev enp1s0 up sudo ip link set dev enp2s0 up Interfaces will recognize one each other and for 1Gbit they turn orange light on, that is OK. I set routing: sudo ip netns exec ns1 ip route add 192.168.22.0/24 via 192.168.21.21 sudo ip route add 192.168.21.0/24 via 192.168.22.22 Now Ubuntu knows how to send packets in ns1 and in root namespaces. I send some traffic, both interfaces start blinking with green: sudo ip netns exec ns1 ping 192.168.22.22 ping 192.168.21.21 I use iperf3 to generate more traffic, e.g.: sudo ip netns exec ns1 iperf3 -s --bind 192.168.21.21 iperf3 -c 192.168.21.21 -b 20M Lazy one may assign addresses in the same network like 192.168.21.21/24 and 192.168.21.22/24 that makes routing extra, but I prefer to have more controllable setup.
1 год назад