summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAiden Woodruff <aiden@aidenw.net>2024-03-23 16:27:29 -0500
committerAiden Woodruff <aiden@aidenw.net>2024-03-23 16:27:29 -0500
commitc8db9305ca66c428f7690db1d00d07b2cac44776 (patch)
tree93d02198f16673e8510e642630df3440fa6f0b30
parente4df9c3d5e873630247bf6e42f56fe4388080727 (diff)
downloadwjail-c8db9305ca66c428f7690db1d00d07b2cac44776.tar.gz
wjail-c8db9305ca66c428f7690db1d00d07b2cac44776.tar.bz2
wjail-c8db9305ca66c428f7690db1d00d07b2cac44776.zip
Replace bridge with NAT forwarding
Remove unnecessary netdown.sh Signed-off-by: Aiden Woodruff <aiden@aidenw.net>
-rwxr-xr-xnetdown.sh4
-rwxr-xr-xnetup.sh38
2 files changed, 27 insertions, 15 deletions
diff --git a/netdown.sh b/netdown.sh
deleted file mode 100755
index da8b49e..0000000
--- a/netdown.sh
+++ /dev/null
@@ -1,4 +0,0 @@
1#!/bin/sh
2
3brctl delbr br-wjail
4ip netns del gitbot
diff --git a/netup.sh b/netup.sh
index 56dd0f2..8b42697 100755
--- a/netup.sh
+++ b/netup.sh
@@ -1,23 +1,39 @@
1#!/bin/sh 1#!/bin/sh
2 2
3if ! [ -f /srv/gitbot/wjail.pid ]; then 3if [ "$(id -u)" -ne 0 ]; then
4echo "You are not root."
5exit 1
6fi
7
8pidfile=/srv/gitbot/wjail.pid
9
10if ! [ -f "$pidfile" ]; then
4echo "wjail not running." 11echo "wjail not running."
5exit 1 12exit 1
6fi 13fi
7 14
8PID=$(cat /srv/gitbot/wjail.pid) 15PID="$(cat "$pidfile")"
9 16
17# Attach iproute2 netns
10ip netns attach gitbot $PID 18ip netns attach gitbot $PID
19
20# Add veth devices
11ip link add veth-wjail type veth peer veth0 netns gitbot 21ip link add veth-wjail type veth peer veth0 netns gitbot
12ifconfig veth-wjail 10.1.1.1/24 up
13ip netns exec gitbot ifconfig veth0 10.1.1.2/24 up
14 22
15# Bridge veth-wjail to eth0 23# Assign ip addresses
16brctl addbr br-wjail 24ip addr add 10.1.1.1/24 dev veth-wjail
17brctl addif br-wjail veth-wjail 25ip netns exec gitbot ip addr add 10.1.1.2/24 dev veth0
18brctl addif br-wjail eth0
19 26
20# Bring interfaces up 27# Bring interfaces up
21ifconfig br-wjail up 28ip link set veth-wjail up
22ifconfig eth0 up 29ip netns exec gitbot ip link set veth0 up
23ifconfig veth-wjail 30
31# Assign default gateway
32ip netns exec gitbot route add default gw 10.1.1.1
33
34# Enable IP forwarding
35echo 1 > /proc/sys/net/ipv4/ip_forward
36
37# Add NAT forwarding rule
38iptables -t nat -A POSTROUTING -s 10.1.1.2/16 -j MASQUERADE
39