Last active
January 21, 2025 01:25
-
-
Save kona3266/4da9a0e22abf37272461ca9b4676bfc1 to your computer and use it in GitHub Desktop.
tc action mirred
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ip netns add t1 | |
ip netns add t2 | |
ip link add t1 type veth peer name t11 | |
ip link add t2 type veth peer name t22 | |
ip link set t11 netns t1 | |
ip link set t22 netns t2 | |
ip netns exec t1 ip link set t11 address ee:ee:ee:ee:ee:02 | |
ip netns exec t1 ip link set t11 up | |
ip netns exec t2 ip link set t22 address ee:ee:ee:ee:ee:03 | |
ip netns exec t2 ip link set t22 up | |
ip link set t1 up | |
ip link set t2 up | |
ip netns exec t1 ip addr add 1.1.1.2/24 dev t11 | |
ip netns exec t2 ip addr add 1.1.1.3/24 dev t22 | |
tc qdisc add dev t1 handle ffff: ingress | |
tc filter add dev t1 parent ffff: u32 match u32 0 0 action mirred egress redirect dev t2 | |
tc qdisc add dev t2 handle ffff: ingress | |
tc filter add dev t2 parent ffff: u32 match u32 0 0 action mirred egress redirect dev t1 | |
ip netns exec t1 ping -c 1 1.1.1.3 | |
ip netns exec t2 ping -c 1 1.1.1.2 | |
ip netns del t1 | |
ip netns del t2 |
Comments are disabled for this gist.