1
0
Fork 0

split network setup in different scripts

master
Pratham Patel 3 months ago
parent e815d741d7
commit de4b076404

@ -0,0 +1,34 @@
#!/usr/bin/env bash
# bold/normal font-stuff
BOLD=$(tput bold)
NORM=$(tput sgr0)
# exit if USER!=root
if [ ${EUID} -ne 0 ]
then
echo "Please run as root, tested with \`sudo\`"
exit 1
fi
WIRED_INTERFACES=$(ip -br l | grep 'enp\|eth' | awk '{print $1}')
TOTAL_INTERFACES=$(echo "$WIRED_INTERFACES" | wc -l)
# exit if (num of interfaces)!=2
if [ ${TOTAL_INTERFACES} -eq 2 ]
then
export INTF_WAN=$(echo "$WIRED_INTERFACES" | head -n 1)
export INTF_LAN=$(echo "$WIRED_INTERFACES" | tail -n 1)
export CON_WAN=$(nmcli -g name,device connection show | grep "$INTF_WAN" | cut -f1 -d":" | head -n 1)
export CON_LAN=$(nmcli -g name,device connection show | grep "$INTF_LAN" | cut -f1 -d":" | tail -n 1)
export BRIDGE_INTERFACE=lanbrg0
else
echo "Sorry... Could not detect at-least 2 NICs"
exit 1
fi
# Enable IPv4 packet forwarding
sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g' /etc/sysctl.conf || echo "net.ipv4.ip_forward=1" | tee -a /etc/sysctl.conf
echo "Using ${BOLD}$INTF_WAN${NORM} ($CON_WAN) as ${BOLD}WAN${NORM}"
echo "Using ${BOLD}$INTF_LAN${NORM} ($CON_LAN) as ${BOLD}LAN${NORM}"

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -x
sed -i "s/.*INTERFACES.*/INTERFACES=\"$INTF_LAN\"/g"
Loading…
Cancel
Save