-
Notifications
You must be signed in to change notification settings - Fork 6
/
ipt_set_udp
executable file
·75 lines (58 loc) · 1017 Bytes
/
ipt_set_udp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# ipt-kit: ipt_set_udp
# Copyright (c) 2014, phiLLip maDDux II (foospidy)
# GNU GENERAL PUBLIC LICENSE
# https://github.com/foospidy/ipt-kit/blob/master/LICENSE#
whoami=`whoami`
if [ 'root' != $whoami ];
then
echo manage_ports must be run as root, run this command again as root, or sudo manage_ports.
exit;
fi
iptables=`which iptables`
if [ -z $iptables ];
then
echo iptables not found, install iptables and try again.
exit;
fi
usage ()
{
echo "usage: ipt_set_tcp <source port> <destination port> [interface]"
}
if [ -z $1 ];
then
usage
exit;
fi
if [ -z $2 ];
then
usage
exit;
fi
if [ -z $3 ];
then
interface=eth0
else
interface=$3
fi
if [[ ! $1 =~ ^[0-9]+$ ]];
then
usage
exit;
fi
if [[ ! $2 =~ ^[0-9]+$ ]];
then
usage
exit;
fi
if (( $1 > 1024 ));
then
echo "You only need to redirect low ports, $1 is not a low port."
exit;
fi
echo
echo
iptables -t nat -A PREROUTING -i $interface -p udp --dport $1 -j REDIRECT --to-port $2
iptables-save
iptables -t nat -L -n -v
echo