Skip to content

Instantly share code, notes, and snippets.

@hbin
Last active May 22, 2022 16:32
Show Gist options
  • Save hbin/03653b8f5d72d369ab402cb793aa4949 to your computer and use it in GitHub Desktop.
Save hbin/03653b8f5d72d369ab402cb793aa4949 to your computer and use it in GitHub Desktop.
Docker OpenWrt no internet access

Problem to Solve:

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment