Skip to content

Instantly share code, notes, and snippets.

@larsbrinkhoff
Last active May 13, 2023 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsbrinkhoff/694c76e03bcf7548b91e14d7e9232c33 to your computer and use it in GitHub Desktop.
Save larsbrinkhoff/694c76e03bcf7548b91e14d7e9232c33 to your computer and use it in GitHub Desktop.
Wifi tunneling
In /etc/systemd/scripts I have "sim-network-env":
```
#!/bin/sh
# VDE network environment preparation script
case "$1" in
start)
echo -n "Starting VDE networks: "
# If you want the tun kernel module to be loaded by the script
# uncomment the following
#modprobe tun 2>/dev/null
#while ! lsmod | grep -q "^tun"; do echo Waiting for tun device; sleep 1; done
# Start tap switches
/usr/bin/vde_switch --tap tap0 --sock /tmp/vde.ctl --mode 660 \
--group cmgauger --mgmt /tmp/vde.mgmt --mgmtmode 660 \
--mgmtgroup cmgauger --daemon --numports 48
/usr/bin/vde_switch --tap tap1 --sock /tmp/xnet.ctl --mode 660 \
--group cmgauger --mgmt /tmp/xnet.mgmt --mgmtmode 660 \
--mgmtgroup cmgauger --daemon --numports 24
;;
stop)
echo -n "Stopping VDE networks: "
# Kill VDE switches
pgrep -f vde_switch | xargs kill -TERM
;;
restart|reload)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 0
```
In /etc/systemd/system I have the service sim-network-env.service:
```
[Unit]
Description=Manage VDE Switches
Requires=network.target
Before=dnsmasq.service
After=network.target
[Service]
Type=oneshot
ExecStart=/etc/systemd/scripts/sim-network-env start
ExecStop=/etc/systemd/script/sim-network-env stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
```
:
In /etc/network in the "interfaces" file are the lines:
```
# TAP interface for the VDE2 switch for simulators/VMs
allow-hotplug tap0
iface tap0 inet static
address 172.16.184.1
network 172.16.184.0
netmask 255.255.252.0
up iptables -t nat -A POSTROUTING -s 172.16.184.0/22 -o wlp24s0 -j MASQUERADE
down iptables -t nat -D POSTROUTING -s 172.16.184.0/22 -o wlp24s0 -j MASQUERADE
allow-hotplug tap1
iface tap1 inet static
address 192.168.47.1
network 192.158.47.0
netmask 255.255.255.0
up iptables -t nat -A POSTROUTING -s 192.168.47.0/24 -o wlp24s0 -j MASQUERADE
down iptables -t nat -D POSTROUTING -s 192.168.47.0/24 -o wlp24s0 -j MASQUERADE
```
I do have these in my /etc/dnsmasq.d/ directory:
dnsmasq-tap0.conf:
```
interface=tap0
listen-address=172.16.184.1
bind-interfaces
server=172.16.184.1
domain-needed
bogus-priv
dhcp-range=172.16.186.0,172.16.186.255,255.255.252.0,12h
```
dnsmasq-tap1.conf:
```
interface=tap1
listen-address=192.168.47.1
bind-interfaces
server=192.168.47.1
domain-needed
bogus-priv
dhcp-range=192.168.47.100,192.168.47.200,255.255.255.0,12h
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment