cli tool to modify iptables rules with lxc
This commit is contained in:
commit
7d74d20651
29
ipth.sh
Normal file
29
ipth.sh
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user