LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2020, 10:27 AM   #1
postcd
Member
 
Registered: Oct 2013
Posts: 527

Rep: Reputation: Disabled
iptables NAT prerouting rule does not forward the traffic?


Hello,


on one server, the iptables rule like:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 48280 -j DNAT --to 10.8.0.2:48280


worked to forward server's incoming traffic at mentioned port into the VPN tunnel where the VPN client network interface has IP 10.8.0.2. Port appeared as open.

Now when i tried the same rule on different server, the port appears closed, even i tried to disable client's firewall.


The ifconfig shows the server has only lo, eth0 and tun0 interfaces so eth0 should be correct.


Please what is the commands you would do to discover where the incoming traffic is stuck?


some details about the server:

Redhat based CentOS 7, kernel 3.10, iptables v1.4.21

lsmod|grep nat

Quote:

xt_nat 12681 6

nf_nat_masquerade_ipv4 13430 1 ipt_MASQUERADE

iptable_nat 12875 1

nf_nat_ipv4 14115 1 iptable_nat

nf_nat 26583 3 nf_nat_ipv4,xt_nat,nf_nat_masquerade_ipv4

nf_conntrack 139224 5 nf_nat,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4

ip_tables 27126 5 iptable_security,iptable_filter,iptable_mangle,iptable_nat,iptable_raw

libcrc32c 12644 3 xfs,nf_nat,nf_conntrack

iptables-save|egrep -i "reject|drop|deny"

Quote:

:POST_public_deny - [0:0]

:PRE_public_deny - [0:0]

-A POST_public -j POST_public_deny

-A PRE_public -j PRE_public_deny

:PRE_public_deny - [0:0]

-A PRE_public -j PRE_public_deny

:PRE_public_deny - [0:0]

-A PRE_public -j PRE_public_deny

:FWDI_public_deny - [0:0]

:FWDO_public_deny - [0:0]

:IN_public_deny - [0:0]

-A INPUT -p udp -m udp --dport 1701 -m policy --dir in --pol none -j DROP

-A INPUT -m conntrack --ctstate INVALID -j DROP

-A INPUT -p udp -m udp --dport 1701 -j DROP

-A FORWARD -m conntrack --ctstate INVALID -j DROP

-A FORWARD -j DROP

iptables-save|egrep -i nat

Quote:
*nat

-A PREROUTING -p tcp -m tcp --dport 12345 -j DNAT --to-destination 127.0.0.1:1082

-A PREROUTING -s 107.186.1.0/24 -p tcp -m tcp --dport 21 -j DNAT --to-destination 1.2.3.4:21

-A PREROUTING -i eth0 -p udp -m udp --dport 48281 -j DNAT --to-destination 10.8.0.2:48281

-A PREROUTING -i eth0 -p udp -m udp --dport 8889 -j DNAT --to-destination 10.8.0.2:8889

-A PREROUTING -i eth0 -p tcp -m tcp --dport 48280-j DNAT --to-destination 10.8.0.2:48280

-A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to-source 1.2.3.4
(1.2.3.4 being server's public IP)


Regarding client, it is Windows 10
 
Old 04-16-2020, 10:55 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,700

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by postcd View Post
Hello,
on one server, the iptables rule like:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 48280 -j DNAT --to 10.8.0.2:48280

worked to forward server's incoming traffic at mentioned port into the VPN tunnel where the VPN client network interface has IP 10.8.0.2. Port appeared as open. Now when i tried the same rule on different server, the port appears closed, even i tried to disable client's firewall. The ifconfig shows the server has only lo, eth0 and tun0 interfaces so eth0 should be correct. Please what is the commands you would do to discover where the incoming traffic is stuck?

some details about the server:
Redhat based CentOS 7, kernel 3.10, iptables v1.4.21
Code:
lsmod|grep nat
xt_nat 12681 6
nf_nat_masquerade_ipv4 13430 1 ipt_MASQUERADE
iptable_nat 12875 1
nf_nat_ipv4 14115 1 iptable_nat
nf_nat 26583 3 nf_nat_ipv4,xt_nat,nf_nat_masquerade_ipv4
nf_conntrack 139224 5 nf_nat,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4
ip_tables 27126 5 iptable_security,iptable_filter,iptable_mangle,iptable_nat,iptable_raw
libcrc32c 12644 3 xfs,nf_nat,nf_conntrack
Code:
iptables-save|egrep -i "reject|drop|deny"
:POST_public_deny - [0:0]
:PRE_public_deny - [0:0]
-A POST_public -j POST_public_deny
-A PRE_public -j PRE_public_deny
:PRE_public_deny - [0:0]
-A PRE_public -j PRE_public_deny
:PRE_public_deny - [0:0]
-A PRE_public -j PRE_public_deny
:FWDI_public_deny - [0:0]
:FWDO_public_deny - [0:0]
:IN_public_deny - [0:0]
-A INPUT -p udp -m udp --dport 1701 -m policy --dir in --pol none -j DROP
-A INPUT -m conntrack --ctstate INVALID -j DROP
-A INPUT -p udp -m udp --dport 1701 -j DROP
-A FORWARD -m conntrack --ctstate INVALID -j DROP
-A FORWARD -j DROP
Code:
iptables-save|egrep -i nat
*nat
-A PREROUTING -p tcp -m tcp --dport 12345 -j DNAT --to-destination 127.0.0.1:1082
-A PREROUTING -s 107.186.1.0/24 -p tcp -m tcp --dport 21 -j DNAT --to-destination 1.2.3.4:21
-A PREROUTING -i eth0 -p udp -m udp --dport 48281 -j DNAT --to-destination 10.8.0.2:48281
-A PREROUTING -i eth0 -p udp -m udp --dport 8889 -j DNAT --to-destination 10.8.0.2:8889
-A PREROUTING -i eth0 -p tcp -m tcp --dport 48280-j DNAT --to-destination 10.8.0.2:48280
-A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to-source 1.2.3.4
(1.2.3.4 being server's public IP) Regarding client, it is Windows 10
You have been asking about and using iptables for over SIX YEARS now, and have posted many similar questions in the past:
https://www.linuxquestions.org/quest...ip-4175495510/
https://www.linuxquestions.org/quest...id-4175667512/
https://www.linuxquestions.org/quest...es-4175506598/
https://www.linuxquestions.org/quest...ot-4175503912/

...and pay particular attention to the last post in this thread:
https://www.linuxquestions.org/quest...ml#post5742851

Again; we know nothing about your internal network, what IP addresses are in use on this server (past the one you posted), nor how you have determined the 'port appears closed'. Are you not able to look through the many, MANY threads you've opened in the past about iptables/firewalls/networking, and apply ANYTHING you've been told in the past???

Have you checked to see if IP forwarding is turned on???? And since you configured one server, why can't you use the EXACT SAME RULES (with small modifications, since the systems are obviously not the same), on the new system? You've been told several times in the past about how to backup and restore rule-sets, so that should be trivial for you to do.

::EDIT::
Some other resources you might want to reference. MANY references to prerouting and NAT'ing:
https://www.lowendtalk.com/discussio...ted-in-any-lan
https://www.lowendtalk.com/discussio...work-admin-vps
http://www.vpnforums.com/index.php?a...=topics;u=3136
https://forums.cpanel.net/threads/ho...wntime.605855/

Last edited by TB0ne; 04-16-2020 at 01:58 PM.
 
Old 04-16-2020, 07:55 PM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by postcd View Post
Now when i tried the same rule on different server, the port appears closed, even i tried to disable client's firewall.
What do you mean by "appears closed"?
Quote:
Please what is the commands you would do to discover where the incoming traffic is stuck?
I would use commands like these:
Code:
tcpdump -v -i eth0 port 48280
tcpdump -v -i tun0
Or perhaps any instead of eth0 and tun0. If you have a GUI, wireshark is very comfortable for filtering and drilling down.
I would also use tcpdump or wireshark on the other side of the tunnel. Wireshark has a Windows edition, too, and tcpdump can be used on Windows via Cygwin if there is no native equivalent.

Other suggestions: Check your netfilter rules again. Is there a rule before the DNAT that might interfere? Also, add a logging rule to the netfilter ruleset (-j LOG).

Last edited by berndbausch; 04-16-2020 at 08:03 PM.
 
1 members found this post helpful.
Old 04-16-2020, 07:57 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,700

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by berndbausch View Post
What do you mean by "appears closed"?

I would use tcpdump.
He's familiar with that command, berndbausch:
https://www.linuxquestions.org/quest...ow-4175667621/
 
Old 04-16-2020, 08:10 PM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by TB0ne View Post
He's familiar with that command, berndbausch:
https://www.linuxquestions.org/quest...ow-4175667621/
Yes, but unlike you I am not an archaelogist
 
Old 04-17-2020, 07:23 AM   #6
postcd
Member
 
Registered: Oct 2013
Posts: 527

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
What do you mean by "appears closed"?
Sorry, forgot to mention this. It means the software on client has a tool that check its incoming port and report closed status. Also the web based third party port checker like https://www.yougetsignal.com/tools/open-ports/ reports the same.

Quote:
Originally Posted by berndbausch View Post
I would use commands like these:
Code:
tcpdump -v -i eth0 port 48280
tcpdump -v -i tun0
...
wireshark is very comfortable for filtering and drilling down.
Thank you for this. I spent one hour trying to install Cygwin on Windows and npcap + windump.exe, but unable to find the tcpdump or no output. I am not interested to waste more of my time setting that. So i ran Wireshark. It seems to be pretty intuitive as you say. It has an flag/bookmark in the filtering field where i can define single port to filter and also in my case the tun0 interface to listen on. Then during capturing i click arrow at the end of the filtering field to apply the filter. It shows no captured output. So no traffic reaching client on that port. But on the server, Yours mentioned command shows alot of output. For just several seconds:

197 packets captured
1267 packets received by filter
915 packets dropped by kernel

sample:
Quote:
14:23:12.123456 IP (tos 0x0, ttl 114, id 28290, offset 0, flags [DF], proto TCP (6), length 52)
hostnamehere.62421 > myhostnamehere.58281: Flags [S], cksum 0x3d05 (correct), seq 4092734578, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
So the traffic is not forwarded or is dropped/denied somehow? @berndbausch please what to do now?
/etc/sysctl.conf shows the forwarding is enabled. (net.ipv4.ip_forward = 1)
Firewall details i have shown in my first post.
And as mentioned, on the client i tried to disable firewall during the capture, so i expect the problem to be on the server.

Quote:
Originally Posted by berndbausch View Post
Check your netfilter rules again. Is there a rule before the DNAT that might interfere?
I does not look like that right? Part of the "iptables -L -t nat" output:
Quote:
PREROUTING_ZONES all -- anywhere anywhere
DNAT tcp -- anywhere anywhere tcp dpt:12345 to:127.0.0.1:1082
DNAT tcp -- iphere.0/24 anywhere tcp dpt:ftp to:myserviphere:21
DNAT udp -- anywhere anywhere udp dpt:48281 to:10.8.0.2:48281
DNAT udp -- anywhere anywhere udp dpt:ddi-udp-2 to:10.8.0.2:8889
DNAT tcp -- anywhere anywhere tcp dpt:48280 to:10.8.0.2:48280
Quote:
Originally Posted by berndbausch View Post
Also, add a logging rule to the netfilter ruleset (-j LOG).
I tried various commands, like
Quote:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 48280 -j LOG
but it logged no output into /var/log/messages

Then this one started logging something: iptables -A INPUT -j LOG
tail -f /var/log/messages
Yet, it shows no traffic that match the port of my interest:
tail -f /var/log/messages|grep 48280
Despite the "tcpdump -v -i eth0 port 48280" has quite intensive traffic output. What would you suggest to try @berndbausch

Last edited by postcd; 04-17-2020 at 07:26 AM.
 
Old 04-17-2020, 08:10 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,700

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by berndbausch View Post
Yes, but unlike you I am not an archaelogist
This particular poster does the same thing in pretty much every thread. I remembered seeing something related, so I did a quick search.
 
Old 04-17-2020, 08:19 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,700

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by postcd View Post
Sorry, forgot to mention this. It means the software on client has a tool that check its incoming port and report closed status. Also the web based third party port checker like https://www.yougetsignal.com/tools/open-ports/ reports the same.

Thank you for this. I spent one hour trying to install Cygwin on Windows and npcap + windump.exe, but unable to find the tcpdump or no output. I am not interested to waste more of my time setting that.
And it didn't occur to you to run tcpdump on the LINUX system??? And since you spent an hour trying to install Cygwin (for some reason), it surprising you couldn't just put "install tcpdump on windows" into Google, and press ENTER...one of the first hit is a Windows version of it: https://www.microolap.com/products/network/tcpdump/

Quote:
So i ran Wireshark. It seems to be pretty intuitive as you say. It has an flag/bookmark in the filtering field where i can define single port to filter and also in my case the tun0 interface to listen on. Then during capturing i click arrow at the end of the filtering field to apply the filter. It shows no captured output. So no traffic reaching client on that port. But on the server, Yours mentioned command shows alot of output. For just several seconds:

197 packets captured
1267 packets received by filter
915 packets dropped by kernel

sample:


So the traffic is not forwarded or is dropped/denied somehow? @berndbausch please what to do now?
/etc/sysctl.conf shows the forwarding is enabled. (net.ipv4.ip_forward = 1)
Which is what I told you in my first reply...
Quote:
Firewall details i have shown in my first post. And as mentioned, on the client i tried to disable firewall during the capture, so i expect the problem to be on the server.

I does not look like that right? Part of the "iptables -L -t nat" output: I tried various commands, like but it logged no output into /var/log/messages Then this one started logging something: iptables -A INPUT -j LOG
tail -f /var/log/messages
Yet, it shows no traffic that match the port of my interest:
tail -f /var/log/messages|grep 48280
Despite the "tcpdump -v -i eth0 port 48280" has quite intensive traffic output. What would you suggest to try @berndbausch
Again, as you've been told many, MANY times over the years, we'd suggest you show some actual effort and thought of your own for a change. You literally have one server that WORKS, that you can look at.

COMPARE THE TWO...there has to be a difference somewhere. When you find it, MAKE IT MATCH. You also (AGAIN) don't tell us what environment you're in, tell us anything about your network topology, where these things run through, etc. Did you bother to check the DMZ? Hardware firewall??? You have to be running through those things in order to touch a public IP address. You were asked all of this in post #2, yet (as usual), don't supply any relevant information.

You've been working with iptables/ufw for SEVEN YEARS; you have been handed exact commands for NAT'ing and forwarding, but each time you need to change something, you don't seem to be able to apply anything you've been told or learned, and instead ask for a handout.

Last edited by TB0ne; 04-17-2020 at 08:23 AM.
 
Old 04-17-2020, 09:34 AM   #9
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
To find out where traffic disappears, you trace the interfaces through which traffic flows. Once you know where it disappears, you look at your netfilter rules once more.

I don't know which interface you traced when receiving this packet:
Code:
14:23:12.123456 IP (tos 0x0, ttl 114, id 28290, offset 0, flags [DF], proto TCP (6), length 52)
hostnamehere.62421 > myhostnamehere.58281: Flags [S], cksum 0x3d05 (correct), seq 4092734578, win 8192, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
but in any case it's neither coming from nor going to port 48280, therefore irrelevant.

Quote:
Originally Posted by postcd View Post
but it logged no output into /var/log/messages

Then this one started logging something: iptables -A INPUT -j LOG
tail -f /var/log/messages
Yet, it shows no traffic that match the port of my interest
tail -f /var/log/messages|grep 48280
This means that packets with port 48280 match an earlier rule and don't reach the LOG rule. You could analyze the rules and/or move the LOG rule to an earlier position.
 
Old 04-17-2020, 09:56 AM   #10
postcd
Member
 
Registered: Oct 2013
Posts: 527

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
You could analyze the rules and/or move the LOG rule to an earlier position.
So i tried "iptables -I INPUT -j LOG"
The client's Wireshark shows some TCP connections at that port 48280, but when the source is some unknown remote IP, then the connection is red with flags RST, ACK.

I found this tool can tell the port status:
https://check-host.net/check-tcp
https://check-host.net/check-udp
and it seems to properly report udp port status as "open or filtered" and the non-forwarded UDP port status as closed. But it always report closed in case of a TCP. So the problem looks to be in a TCP (forwarding on the server?), but i am really unsure why UDP yes and TCP no.


# iptables -L FORWARD

Quote:
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT all -- 10.8.0.0/24 anywhere
DROP all -- anywhere anywhere ctstate INVALID
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
ACCEPT all -- 192.168.42.0/24 192.168.42.0/24
ACCEPT all -- anywhere 192.168.43.0/24 ctstate RELATED,ESTABLISHED
ACCEPT all -- 192.168.43.0/24 anywhere
DROP all -- anywhere anywhere

# iptables -L -t nat|grep DNAT

Quote:
DNAT tcp -- anywhere anywhere tcp dpt:12345 to:127.0.0.1:1082
DNAT tcp -- ciziip.0/24 anywhere tcp dpt:ftp to:ipmehoserveru:21
DNAT udp -- anywhere anywhere udp dpt:ddi-udp-2 to:10.8.0.2:8889
DNAT tcp -- anywhere anywhere tcp dpt:48280 to:10.8.0.2:48280
DNAT tcp -- anywhere anywhere tcp dpt:48281 to:10.8.0.2:48281
DNAT udp -- anywhere anywhere udp dpt:48281 to:10.8.0.2:48281
DNAT udp -- anywhere anywhere udp dpt:48280 to:10.8.0.2:48280

Last edited by postcd; 04-17-2020 at 11:00 AM.
 
Old 04-17-2020, 10:35 AM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,700

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by postcd View Post
You mean iptables -I INPUT -j log ?
Would it be helpful in case i discovered (using Wireshark) that the UDP traffic go through to the client, but TCP traffic somehow is not forwarded nor is visible in server's iptables log output but exist in server's tcpdump?
Or you can *AGAIN* use tcpdump for Windows, since you've been using it for some time. And since you want to trace what's going on in the logs for iptables, wouldn't it be obvious to look at that log file??
Quote:
I found this tool can tell the port status:
https://check-host.net/check-tcp
https://check-host.net/check-udp
and it seems to properly report udp port status as "open or filtered" and the non-forwarded UDP port status as closed. But it always report closed in case of a TCP. So the problem looks to be in a TCP (forwarding on the server?), but i am really unsure why UDP yes and TCP no.
**AGAIN**, since you don't seem to be understanding; PROVIDE DETAILS. You are looking at an ****EXTERNAL ADDRESS****....this most probably involves some sort of firewall/DMZ setup. Since you've been working with such things for at least SEVEN YEARS, you should already know that when you want a new server to be allowed to receive/send traffic externally, that you have to **CONFIGURE THE FIREWALL AND DMZ TO ALLOW IT**

Have you done this? Have you checked this???
Quote:
# iptables -L FORWARD
# iptables -L -t nat|grep DNAT
highlighted rule is the one responsible for the tcp port forwarding which results in port closed detection on online testers and in the app that using the port.. Thank you
Great; so AGAIN, as has been explained to you dozens of times over the past seven years: FIND THE DIFFERENCE BETWEEN THE WORKING AND NON WORKING SYSTEM. One works; the other doesn't. Since you set one up, you should easily be able to set another one up....you are familiar with EVERY PIECE of this, and it's been explained to you over and over again, on this site and many others.

You are not providing details about your network topology, just posting rulesets and asking us to diagnose them for you. After so many years, are you not able to do any sort of diagnostics on your own?? Are you unable to use the tools that people have told you about dozens of times??? Why can you not apply anything you've been told?
 
Old 04-17-2020, 07:12 PM   #12
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I have to admit that I know nothing about your architecture, about Windows, a client, virtual machines and so on. I know you have a Linux server with a NIC eth0 and a tunnel endpoint tun0. Traffic to port 48280 is supposed to enter via eth0 and get forwarded to the tunnel. Is that correct?

If so, first check if traffic arrives at eth0 at all. tcpdump can reveal that.

Next, check if those packets flow through tun0. If so, the problem is not your netfilter rules. If not, I would first check what the routing tables do with destination 10.8.0.2. Is it routed to tun0 at all? If not, fix this.

In case traffic does arrive at eth0, the routing rules are correct and traffic does NOT go through tun0, you rework your netfilter rules.
 
1 members found this post helpful.
Old 04-18-2020, 02:43 AM   #13
postcd
Member
 
Registered: Oct 2013
Posts: 527

Original Poster
Rep: Reputation: Disabled
Lightbulb

It seems solved now. The connections started going through (and recorded on server under tun0 interface - tcpdump -i tun0 tcp port 48280) when i removed the forwarding rule highlighted below:

Quote:
iptables -L FORWARD --line-numbers
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 10.8.0.0/24 anywhere
2 ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
3 DROP all -- anywhere anywhere ctstate INVALID
4 ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
5 ACCEPT all -- anywhere anywhere
6 ACCEPT all -- 192.168.42.0/24 192.168.42.0/24
7 ACCEPT all -- anywhere 192.168.43.0/24 ctstate RELATED,ESTABLISHED
8 ACCEPT all -- 192.168.43.0/24 anywhere
9 DROP all -- anywhere anywhere

Below are other details even the above mentioned action solved the issue of this forum topic, i am leaving it here if you are insterested to know:

Quote:
Originally Posted by berndbausch View Post
Traffic to port 48280 is supposed to enter via eth0 and get forwarded to the tunnel. Is that correct?
Thank you for your reply. Yes, that is what i wanted to achieve.

Quote:
Originally Posted by berndbausch View Post
If so, first check if traffic arrives at eth0 at all. tcpdump can reveal that.
yes, it does arrive, because on the server, i am seeing quite alot of connection from various IPs when running:
tcpdump tcp port 48280
tcpdump -i eth0 tcp port 48280
Sample:
Quote:
09:25:01.3452698 IP thirdpartyip.6803 > myserverhostname.48280: Flags [S], seq 568199270, win 64240, options [mss 1412,nop,wscale 8,nop,nop,sackOK], length 0
but "tcpdump -i tun0 tcp port 48280" does not shown any TCP connections

Quote:
Originally Posted by berndbausch View Post
Next, check if those packets flow through tun0.
How do i do it on the server? i mentioned a few lines above that i see the TCP traffic on eth0, but not on tun0.. + on the client i confirm that i received no TCP connections at that port, only UDP ones.

I think that here comes your suggestion:
Quote:
I would first check what the routing tables do with destination 10.8.0.2. Is it routed to tun0 at all?
# iptables-save|egrep -i "tun|48280"
Quote:
-A PREROUTING -i eth0 -p tcp -m tcp --dport 48280:48285 -j DNAT --to-destination 10.8.0.2
-A PREROUTING -i eth0 -p udp -m udp --dport 48280:48285 -j DNAT --to-destination 10.8.0.2
# ip route show|grep tun
Quote:
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.1
# iptables-save|egrep -i "10.8.0|tun"
Quote:
-A PREROUTING -i eth0 -p udp -m udp --dport 8889 -j DNAT --to-destination 10.8.0.2:8889
-A PREROUTING -i eth0 -p tcp -m tcp --dport 48280:48285 -j DNAT --to-destination 10.8.0.2
-A PREROUTING -i eth0 -p udp -m udp --dport 48280:48285 -j DNAT --to-destination 10.8.0.2
-A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to-source serverpublicIPhere
-A FORWARD -s 10.8.0.0/24 -j ACCEPT
(10.8.0.2 is the openvpn interface address that is valid on the client computer)

# iptables -L FORWARD
Quote:
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT all -- 10.8.0.0/24 anywhere
DROP all -- anywhere anywhere ctstate INVALID
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
ACCEPT all -- 192.168.42.0/24 192.168.42.0/24
ACCEPT all -- anywhere 192.168.43.0/24 ctstate RELATED,ESTABLISHED
ACCEPT all -- 192.168.43.0/24 anywhere
DROP all -- anywhere anywhere
# iptables -t nat -L
Quote:
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
PREROUTING_direct all -- anywhere anywhere
PREROUTING_ZONES_SOURCE all -- anywhere anywhere
PREROUTING_ZONES all -- anywhere anywhere
DNAT tcp -- anywhere anywhere tcp dpt:12345 to:127.0.0.1:1082
DNAT tcp -- 1.2.3.0/24 anywhere tcp dpt:ftp to:9.8.7.6:21
DNAT udp -- anywhere anywhere udp dpt:ddi-udp-2 to:10.8.0.2:8889
DNAT tcp -- anywhere anywhere tcp dpts:48280:48285 to:10.8.0.2
DNAT udp -- anywhere anywhere udp dpts:48280:48285 to:10.8.0.2

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
OUTPUT_direct all -- anywhere anywhere

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
POSTROUTING_direct all -- anywhere anywhere
POSTROUTING_ZONES_SOURCE all -- anywhere anywhere
POSTROUTING_ZONES all -- anywhere anywhere
SNAT all -- 10.8.0.0/24 !10.8.0.0/24 to:myserverpubliciphere
MASQUERADE all -- 192.168.42.0/24 anywhere
MASQUERADE all -- 192.168.43.0/24 anywhere policy match dir out pol none
MASQUERADE all -- anywhere anywhere
MASQUERADE all -- anywhere anywhere

Chain OUTPUT_direct (1 references)
target prot opt source destination

Chain POSTROUTING_ZONES (1 references)
target prot opt source destination
POST_public all -- anywhere anywhere [goto]
POST_public all -- anywhere anywhere [goto]

Chain POSTROUTING_ZONES_SOURCE (1 references)
target prot opt source destination

Chain POSTROUTING_direct (1 references)
target prot opt source destination

Chain POST_public (2 references)
target prot opt source destination
POST_public_log all -- anywhere anywhere
POST_public_deny all -- anywhere anywhere
POST_public_allow all -- anywhere anywhere

Chain POST_public_allow (1 references)
target prot opt source destination

Chain POST_public_deny (1 references)
target prot opt source destination

Chain POST_public_log (1 references)
target prot opt source destination

Chain PREROUTING_ZONES (1 references)
target prot opt source destination
PRE_public all -- anywhere anywhere [goto]
PRE_public all -- anywhere anywhere [goto]

Chain PREROUTING_ZONES_SOURCE (1 references)
target prot opt source destination

Chain PREROUTING_direct (1 references)
target prot opt source destination

Chain PRE_public (2 references)
target prot opt source destination
PRE_public_log all -- anywhere anywhere
PRE_public_deny all -- anywhere anywhere
PRE_public_allow all -- anywhere anywhere

Chain PRE_public_allow (1 references)
target prot opt source destination

Chain PRE_public_deny (1 references)
target prot opt source destination

Chain PRE_public_log (1 references)
target prot opt source destination
I lso tried following but that NOT opened port on its own:
when i exported iptables (iptables-save > /etc/sysconfig/iptables_18.4.2020)
created copy (cp -p /etc/sysconfig/iptables_18.4.2020 /etc/sysconfig/iptables_18.4.2020_mod)
edited the copy (vi /etc/sysconfig/iptables_18.4.2020_mod)
append:
-A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source myserveriphere
after line:
-A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to-source myserveriphere
save and import into firewall (iptables-restore < /etc/sysconfig/iptables_18.4.2020_mod)
i then moved FORWARD rule:
FORWARD -s 10.8.0.0/24 -j ACCEPT
to the top

Last edited by postcd; 04-18-2020 at 04:38 AM.
 
Old 04-18-2020, 06:32 AM   #14
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
You did all the checks that I recommended. You confirmed that 48280 traffic arrives at eth0 and does not flow through tun0 (tcpdump -i tun0 confirms that). You checked that traffic to 10.8.0.0 is indeed routed to tun0. All this is fine.

So the only reason I can see is a problem with your netfilter rules. They are rather complex - I guess you have a firewall that creates all these rules. The problem is that you interfere with the firewall by adding a DNAT rule, and that it's hard to get a grip on that interference.

You seem to have the problem even when the firewall is off. But when it is off, the rules are simpler, I guess, which would make it easier to find out how packets are passed through netfilter.

As far as I know, the only ways to deal with it are, again, manually checking the rules, perhaps performing a netfilter simulation on paper. Or using LOG rules that you place at useful positions in the rule set. I am not aware of a netfilter analyzer (but by all means, don't believe me).

If you have found a solution, great.
 
2 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables subnet traffic masquerade work but prerouting end in 111: connection refused g1thub Linux - Networking 1 08-21-2019 09:32 AM
Iptables nat postrouting and prerouting, done right for this network? apikalegusta Linux - Security 4 03-27-2015 10:45 AM
Prerouting with DROP as the default rule loureed4 Linux - Security 15 01-02-2015 03:20 PM
[SOLVED] Debugging NAT / prerouting issues (iptables) Vlad.BG Linux - Networking 1 12-07-2014 05:22 AM
iptables nat prerouting redirect issue - rhel 5.5 64-bit wischad Linux - Networking 1 11-12-2010 08:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration