Update iptables.sh

This commit is contained in:
MarkusMcNugen 2018-02-11 22:53:57 -05:00 committed by GitHub
parent 3568de3231
commit 07701650a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,13 +30,13 @@ for lan_network_item in "${lan_network_list[@]}"; do
# strip whitespace from start and end of lan_network_item # strip whitespace from start and end of lan_network_item
lan_network_item=$(echo "${lan_network_item}" | sed -e 's~^[ \t]*~~;s~[ \t]*$~~') lan_network_item=$(echo "${lan_network_item}" | sed -e 's~^[ \t]*~~;s~[ \t]*$~~')
echo "[info] Adding ${lan_network_item} as route via docker eth0" echo "$(date) [info] Adding ${lan_network_item} as route via docker eth0"
ip route add "${lan_network_item}" via "${DEFAULT_GATEWAY}" dev eth0 ip route add "${lan_network_item}" via "${DEFAULT_GATEWAY}" dev eth0
lancount=$((lancount+1)) lancount=$((lancount+1))
done done
echo "[info] ip route defined as follows..." | ts '%Y-%m-%d %H:%M:%.S' echo "$(date) [info] ip route defined as follows..."
echo "--------------------" echo "--------------------"
ip route ip route
echo "--------------------" echo "--------------------"
@ -45,7 +45,7 @@ echo "--------------------"
### ###
if [[ "${DEBUG}" == "true" ]]; then if [[ "${DEBUG}" == "true" ]]; then
echo "[debug] Modules currently loaded for kernel" ; lsmod echo "$(date) [debug] Modules currently loaded for kernel" ; lsmod
fi fi
# check we have iptable_mangle, if so setup fwmark # check we have iptable_mangle, if so setup fwmark
@ -54,7 +54,7 @@ iptable_mangle_exit_code=$?
if [[ $iptable_mangle_exit_code == 0 ]]; then if [[ $iptable_mangle_exit_code == 0 ]]; then
echo "[info] iptable_mangle support detected, adding fwmark for tables" | ts '%Y-%m-%d %H:%M:%.S' echo "$(date) [info] iptable_mangle support detected, adding fwmark for tables"
# setup route for deluge webui using set-mark to route traffic for port 8080 to eth0 # setup route for deluge webui using set-mark to route traffic for port 8080 to eth0
echo "8080 webui" >> /etc/iproute2/rt_tables echo "8080 webui" >> /etc/iproute2/rt_tables
@ -66,24 +66,24 @@ fi
# identify docker bridge interface name (probably eth0) # identify docker bridge interface name (probably eth0)
docker_interface=$(netstat -ie | grep -vE "lo|tun|tap" | sed -n '1!p' | grep -P -o -m 1 '^[\w]+') docker_interface=$(netstat -ie | grep -vE "lo|tun|tap" | sed -n '1!p' | grep -P -o -m 1 '^[\w]+')
if [[ "${DEBUG}" == "true" ]]; then if [[ "${DEBUG}" == "true" ]]; then
echo "[debug] Docker interface defined as ${docker_interface}" echo "$(date) [debug] Docker interface defined as ${docker_interface}"
fi fi
# identify ip for docker bridge interface # identify ip for docker bridge interface
docker_ip=$(ifconfig "${docker_interface}" | grep -P -o -m 1 '(?<=inet\saddr:)[^\s]+') docker_ip=$(ifconfig "${docker_interface}" | grep -P -o -m 1 '(?<=inet\saddr:)[^\s]+')
if [[ "${DEBUG}" == "true" ]]; then if [[ "${DEBUG}" == "true" ]]; then
echo "[debug] Docker IP defined as ${docker_ip}" echo "$(date) [debug] Docker IP defined as ${docker_ip}"
fi fi
# identify netmask for docker bridge interface # identify netmask for docker bridge interface
docker_mask=$(ifconfig "${docker_interface}" | grep -P -o -m 1 '(?<=Mask:)[^\s]+') docker_mask=$(ifconfig "${docker_interface}" | grep -P -o -m 1 '(?<=Mask:)[^\s]+')
if [[ "${DEBUG}" == "true" ]]; then if [[ "${DEBUG}" == "true" ]]; then
echo "[debug] Docker netmask defined as ${docker_mask}" echo "$(date) [debug] Docker netmask defined as ${docker_mask}"
fi fi
# convert netmask into cidr format # convert netmask into cidr format
docker_network_cidr=$(ipcalc "${docker_ip}" "${docker_mask}" | grep -P -o -m 1 "(?<=Network:)\s+[^\s]+" | sed -e 's~^[ \t]*~~;s~[ \t]*$~~') docker_network_cidr=$(ipcalc "${docker_ip}" "${docker_mask}" | grep -P -o -m 1 "(?<=Network:)\s+[^\s]+" | sed -e 's~^[ \t]*~~;s~[ \t]*$~~')
echo "[info] Docker network defined as ${docker_network_cidr}" | ts '%Y-%m-%d %H:%M:%.S' echo "$(date) [info] Docker network defined as ${docker_network_cidr}"
# input iptable rules # input iptable rules
### ###
@ -172,7 +172,7 @@ iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
# accept output from local loopback adapter # accept output from local loopback adapter
iptables -A OUTPUT -o lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT
echo "[info] iptables defined as follows..." | ts '%Y-%m-%d %H:%M:%.S' echo "$(date) [info] iptables defined as follows..."
echo "--------------------" echo "--------------------"
iptables -S iptables -S
echo "--------------------" echo "--------------------"