From 7d74d20651e08e4e10331662afaa688890e63007 Mon Sep 17 00:00:00 2001 From: marchal Date: Sun, 27 Oct 2019 13:14:55 +0100 Subject: [PATCH] cli tool to modify iptables rules with lxc --- ipth.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ipth.sh diff --git a/ipth.sh b/ipth.sh new file mode 100644 index 0000000..fe001ae --- /dev/null +++ b/ipth.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Script to handle iptables rules when working with lxc + +show_usage() { + echo -e "usage: ./ipth.sh [4/6] [display]" + echo -e "usage: ./ipth.sh [4/6] [add/delete] [interface] [container IP] [port]" + echo -e "example: ./ipth.sh 4 add eth0 10.10.10.10 80" +} + +if [ "$1" = "4" ]; then + program=iptables + ip=$4 +elif [ "$1" = "6" ]; then + program=ip6tables + ip='['"$4"']' +else + show_usage + exit 1; +fi + +if [ "$2" = "add" ]; then + $program -t nat -A PREROUTING -i $3 -p tcp --dport $5 -j DNAT --to $ip:$5 +elif [[ "$2" = "del" || "$2" = "delete" || "$2" = "remove" ]]; then + $program -t nat -D PREROUTING -i $3 -p tcp --dport $5 -j DNAT --to $ip:$5 +elif [[ "$2" = "show" || "$2" = "display" ]]; then + $program -t nat -L +else + show_usage +fi