Gentoo Forums
Gentoo Forums
Quick Search: in
Port Forwarding Script Not Working
View unanswered posts
View posts from last 24 hours

rackathon
 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
r00t440
Tux's lil' helper
Tux's lil' helper


Joined: 13 Sep 2005
Posts: 77

PostPosted: Wed Apr 12, 2006 6:31 am    Post subject: Port Forwarding Script Not Working Reply with quote

Here's a port forwarding script I copied over the internet, can anyone spot any problem with it? It doesn't seem to work as expected. I use ipkungfu as my firewall script.
I've been working on this for almost a whole day, I'm running out of ideas. Thanks in advance to anyone who can help me.

Code:
PORTFWIP="192.168.2.251"
IPTABLES="/sbin/iptables"
EXTIP="210.1.70.73"
EXTIF="eth2"
INTIF="eth0"
INTIP="192.168.2.254"
INTLAN="192.168.2.0/24"
 
$IPTABLES -A FORWARD -i $EXTIF -o $INTIF -p tcp --dport 6200 -m state \
 --state NEW,ESTABLISHED,RELATED -j ACCEPT
 
 
$IPTABLES -A PREROUTING -t nat -p tcp -d $EXTIP --dport 6200 -m state \
 --state NEW,ESTABLISHED,RELATED -j DNAT --to $PORTFWIP:6200
 
$IPTABLES -t nat -A POSTROUTING -d $PORTFWIP -s $INTLAN -p tcp \
--dport 6200 -m state --state NEW,ESTABLISHED,RELATED -j SNAT \
--to $INTIP


*taken from http://www.linux.com/howtos/IP-Masquerade-HOWTO/forwarders.shtml
Back to top
View user's profile Send private message
mks99
n00b
n00b


Joined: 10 Dec 2004
Posts: 58

PostPosted: Wed Apr 12, 2006 7:53 am    Post subject: Reply with quote

The second rule changes the dest. IP of the packets to $PORTFWIP and passes them to the FORWARD chain. OK.
The first rule allows those packets to be forwarded. OK.
But I don't see any sense in the third rule. Of course, there has to be done some MASQUERADEing since the reply-packets from $PORTFWIP must have their src IP changed to $EXTIP. But this should be accomplished by a rule like
Code:
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE
If you like, you can restrict this to the packets coming from $PORTFWIP with src port 6200.
And I also don't see a rule that allows the response packets from $PORTFWIP to be forwarded. There should be something like
Code:
$IPTABLES -A FORWARD -i $INTIF -s $PORTFWIP -m state RELATED,ESTABLISHED -j ACCEPT

BTW: You have configured your machine to do forwarding at all? I. e.
Code:
echo "1" > /proc/sys/net/ipv4/ip_forward
Back to top
View user's profile Send private message
r00t440
Tux's lil' helper
Tux's lil' helper


Joined: 13 Sep 2005
Posts: 77

PostPosted: Wed Apr 12, 2006 9:29 am    Post subject: Reply with quote

thanks... i tried your suggestions but still i'm totally lost. i've read a guide from gentoo-wiki.com (http://gentoo-wiki.com/HOWTO_setup_a_home-server) and adapted the eMule port-forwarding part, but still no luck. By the way, i'm using ipkungfu as my firewall script. There's a part in ipkungfu's config files which is all about port forwarding and i've tried modifying it. But still port 6200 on my external ip is closed when performing a portscan against it.

I'm very tired now so I guess I'll work on this by tomorrow. I'm gonna try the following:

1. I won't use ipkungfu and try my port forwarding scripts.
2. I'm gonna try my new kernel (I might have missed something from my current kernel)
3. Read my post and hope that somebody has come across with it and was kind enough to offer some suggestions/help. :P

oh by the way, here's the output of "iptables -nvL", this might be of some help:

Code:

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   53  5031 ACCEPT     all  --  eth0   *       192.168.2.0/24       0.0.0.0/0           state NEW
31657 4713K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    0     0 REJECT     udp  --  *      eth2    192.168.2.0/24       0.0.0.0/0           state INVALID reject-with icmp-port-unreachable
   38  1520 REJECT     tcp  --  *      eth2    192.168.2.0/24       0.0.0.0/0           state INVALID reject-with icmp-port-unreachable
    0     0 DROP       all  --  eth2   *       0.0.0.0/0            0.0.0.0/0           recent: CHECK seconds: 120 name: badguy side: source
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x3F limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_flags_ALL: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_flags_NONE: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x29 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_flags_FIN_URG_PSH: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x01 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_PORTSCAN_nmap_XMAS: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x03/0x03 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_flags_SYN_FIN: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x06 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_flags_SYN_RST: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x37 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_SYN_RST_ACK_FIN_URG: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_PORTSCAN_nmap_NULL: '
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x37
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x03/0x03
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x06
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x29
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x3F
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x01
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           state INVALID limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Invalid_TCP_flag: '
    0     0 DROP       all  --  eth2   *       0.0.0.0/0            0.0.0.0/0           state INVALID
    0     0 LOG        icmp --  eth2   *       0.0.0.0/0            0.0.0.0/0           icmp type 13 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_ICMP_Timestamp: '
    0     0 DROP       icmp --  eth2   *       0.0.0.0/0            0.0.0.0/0           icmp type 13
    0     0 syn-flood  tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x17/0x02
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:!0x16/0x02 state NEW limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_New_Not_SYN: '
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:!0x16/0x02 state NEW
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           multiport dports 137,6666
    0     0 DROP       udp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           multiport dports 1434
    0     0 LOG        all  --  eth2   *       10.0.0.0/8           0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       172.16.0.0/12        0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       192.168.0.0/16       0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       127.0.0.0/24         0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       169.254.0.0/16       0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       192.0.2.0/24         0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       198.18.0.0/15        0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       255.255.255.255      0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 DROP       all  --  eth2   *       10.0.0.0/8           0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       172.16.0.0/12        0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       192.168.0.0/16       0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       127.0.0.0/24         0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       169.254.0.0/16       0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       192.0.2.0/24         0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       198.18.0.0/15        0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       255.255.255.255      0.0.0.0/0           

Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  301 17223 ACCEPT     all  --  eth0   *       192.168.2.0/24       0.0.0.0/0           state NEW
    6   378 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           state NEW
44177 6313K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  eth0   *       192.168.2.0/24       0.0.0.0/0           
    0     0 LOG        all  --  eth0   *       0.0.0.1              0.0.0.0/0           LOG flags 0 level 4 prefix `IPKF_IPKungFu --init'
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           recent: CHECK seconds: 120 name: badguy side: source
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x3F limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_flags_ALL: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_flags_NONE: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x29 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_PORTSCAN_nmap_XMAS: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x01 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_PORTSCAN_nmap_FIN: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x03/0x03 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_flags_SYN_FIN: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x06 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_flags_SYN_RST: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x37 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_SYN_RST_ACK_FIN_URG: '
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_PORTSCAN_nmap_NULL: '
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x37
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x03/0x03
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x06
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x29
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x3F
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x01
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x3F/0x00
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           icmp type 8
    3  2501 LOG        tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Invalid_TCP_Flag: '
    3  2501 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID
    0     0 LOG        icmp --  eth2   *       0.0.0.0/0            0.0.0.0/0           icmp type 13 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_ICMP_Timestamp: '
    0     0 DROP       icmp --  eth2   *       0.0.0.0/0            0.0.0.0/0           icmp type 13
   26  1248 syn-flood  tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x17/0x02
    0     0 LOG        tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:!0x16/0x02 state NEW limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_New_Not_SYN: '
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           tcp flags:!0x16/0x02 state NEW
    0     0 DROP       tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           multiport dports 137,6666
    0     0 DROP       udp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           multiport dports 1434
    0     0 LOG        all  --  eth2   *       10.0.0.0/8           0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       172.16.0.0/12        0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       192.168.0.0/16       0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       127.0.0.0/24         0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       169.254.0.0/16       0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       192.0.2.0/24         0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       198.18.0.0/15        0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 LOG        all  --  eth2   *       255.255.255.255      0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_Spoof: '
    0     0 DROP       all  --  eth2   *       10.0.0.0/8           0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       172.16.0.0/12        0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       192.168.0.0/16       0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       127.0.0.0/24         0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       169.254.0.0/16       0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       192.0.2.0/24         0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       198.18.0.0/15        0.0.0.0/0           
    0     0 DROP       all  --  eth2   *       255.255.255.255      0.0.0.0/0           
    0     0 ACCEPT     tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:37312
    0     0 ACCEPT     tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:6112
    0     0 ACCEPT     udp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           state NEW udp dpt:6112
    0     0 ACCEPT     tcp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:6200
    0     0 ACCEPT     udp  --  eth2   *       0.0.0.0/0            0.0.0.0/0           state NEW udp dpt:6200
   44  3090 LOG       !icmp --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix ` IPKF_INPUT_Catch-all: '
   45  3141 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 20 packets, 1360 bytes)
 pkts bytes target     prot opt in     out     source               destination         
51954 7199K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    0     0 LOG        udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:2002 limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `SLAPPER!_rm_-f_/tmp/*bugtraq*'
    0     0 DROP       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:2002
  232 11710 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW

Chain syn-flood (2 references)
 pkts bytes target     prot opt in     out     source               destination         
   26  1248 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 10/sec burst 24
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 3/sec burst 5 LOG flags 0 level 4 prefix `IPKF_SYN_flood: '
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           


I have a static ip.

Thanks mks99 for posting. Sorry, I'm really confused with this iptables thingy.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum