LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Port forwarding (https://www.linuxquestions.org/questions/linux-newbie-8/port-forwarding-869317/)

skjadoon 03-17-2011 11:19 PM

Port forwarding
 
Hi everyone

I want to forward http 9999 port from ppp0 interface (intenet connection) to port 80 on my local server 192.168.1.10.
ppp0 ip is : 124.109.x.x

Currently there is no rule for FORWARD, OUTPUT AND PREROUTING

Rule for POSTROUTING IS: -A POSTROUTING -o ppp0 -j MASQUERADE

routing is also enabled.

NM04 03-18-2011 06:06 AM

why don't you change the port of your server on which it listens.

Regards.

skjadoon 03-18-2011 11:34 PM

I have tried to change the port from 80 to 9999 but face similar problem. I have also allow this port from squid.conf file

NM04 03-27-2011 11:31 PM

Quote:

Originally Posted by skjadoon (Post 4294608)
Hi everyone

I want to forward http 9999 port from ppp0 interface (intenet connection) to port 80 on my local server 192.168.1.10.
ppp0 ip is : 124.109.x.x

skjadoon,

What exactly is your problem, in your this post you said that you want to forward the http 9999 port to http 80. And now you are saying that you tried to change port 80 to port 9999. Need some more info , what exactly you are doing, what is you setup ?

win32sux 03-28-2011 12:27 AM

Quote:

Originally Posted by skjadoon (Post 4294608)
Currently there is no rule for FORWARD, OUTPUT AND PREROUTING

Well, you need a PREROUTING rule.

Ideally, you'd also want a FORWARD rule, with your policy set to DROP.

The OUTPUT chain is irrelevant here. Example:
Code:

iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -p TCP -i ppp0 -o eth0 --dport 80 -d 192.168.1.10 -m state --state NEW -j ACCEPT
iptables -t nat -A PREROUTING -p TCP --dport 9999 -i ppp0 -j DNAT --to-destination 192.168.1.10:80
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

There's actually tons of examples on LQ. Did you search before asking?

skjadoon 03-30-2011 12:28 AM

YES I searched many examples and try all including your sample code. but still when i try to open http://124.109.x.x:9999/ it fails to forward the traffic to 192.168.1.10:80

win32sux 03-30-2011 09:12 PM

Please post the output of:
Code:

iptables -nvL --line-numbers FORWARD
Code:

iptables -nvL -t nat --line-numbers
Code:

route -n
Code:

ifconfig

skjadoon 03-31-2011 02:04 AM

[root@server root]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0D:56:FE:7D:E7
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:88301 errors:0 dropped:0 overruns:0 frame:0
TX packets:77997 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:78495179 (74.8 Mb) TX bytes:15476553 (14.7 Mb)
Interrupt:28 Base address:0xdce0 Memory:fe8e0000-fe900000

eth1 Link encap:Ethernet HWaddr 00:50:BA:D9:4C:B2
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:74942 errors:0 dropped:0 overruns:0 frame:0
TX packets:104755 errors:0 dropped:0 overruns:17 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16123396 (15.3 Mb) TX bytes:102714434 (97.9 Mb)
Interrupt:16 Base address:0x3c00

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1636 errors:0 dropped:0 overruns:0 frame:0
TX packets:1636 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:144722 (141.3 Kb) TX bytes:144722 (141.3 Kb)

ppp0 Link encap:Point-to-Point Protocol
inet addr:124.109.x.x P-t-P:58.65.175.x Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1492 Metric:1
RX packets:88035 errors:0 dropped:0 overruns:0 frame:0
TX packets:77729 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:76189959 (72.6 Mb) TX bytes:13440884 (12.8 Mb)

**************************************************************************************************** ****
[root@pcbserver root]# iptables -nvL FORWARD
Chain FORWARD (policy ACCEPT 1403 packets, 92244 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- ppp0 eth1 0.0.0.0/0 192.168.1.10 tcp dpt:80 state NEW
28 1326 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED

*************************************************************************************************
[root@pcbserver root]# iptables -nvL -t nat
Chain PREROUTING (policy ACCEPT 7199 packets, 512K bytes)
pkts bytes target prot opt in out source destination
0 0 DNAT tcp -- ppp0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:9999 to:192.168.1.10:80

Chain POSTROUTING (policy ACCEPT 1521 packets, 103K bytes)
pkts bytes target prot opt in out source destination
7413 448K MASQUERADE all -- * ppp0 0.0.0.0/0 0.0.0.0/0

Chain OUTPUT (policy ACCEPT 8378 packets, 514K bytes)
pkts bytes target prot opt in out source destination

skjadoon 03-31-2011 02:06 AM

[root@server root]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
58.65.175.x 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
0.0.0.0 58.65.175.x 0.0.0.0 UG 0 0 0 ppp0


All times are GMT -5. The time now is 03:27 AM.