Host want to use OpenWrt as gateway to pass wall.
- My router IP: 192.168.31.1
- My host IP: 192.168.31.2
- OpenWrt container IP: 192.168.31.3
| # File path: /etc/systemd/system/rc-local.service | |
| [Unit] | |
| Description=/etc/rc.local Compatibility | |
| ConditionPathExists=/etc/rc.local | |
| [Service] | |
| Type=forking | |
| ExecStart=/etc/rc.local start | |
| TimeoutSec=0 | |
| StandardOutput=tty | |
| RemainAfterExit=yes | |
| [Install] | |
| WantedBy=multi-user.target |
| # File path: /etc/rc.local | |
| # 1. Create a new macvlan interface | |
| ip link add link enp2s0 mynet type macvlan mode bridge | |
| # 2. Set the IP address | |
| ip addr add 192.168.31.4 dev mynet | |
| ip link set mynet up | |
| # 3. Add route to OpenWrt, after this step, you will be able to ping 192.168.31.3 from the host. | |
| ip route add 192.168.31.3 dev mynet | |
| # 4. Replace with OpenWrt as the default gateway, after this step, you will be able to pass wall from the host. ;) | |
| ip route del default | |
| ip route add default via 192.168.31.3 dev mynet |