Problems activating your account? Send notification email to: admin@post4vps.com
Host4Fun Budget VPS Hosting

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Port Forwarding Problem - Public port to Private Port
#1
Hello, I have a problem with port forwarding

I want to forward the connection from public zone port 22 to private zone port 2222 But I don't know why this command doesn't work

Terminal
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 22 -j DNAT --to 127.0.0.1:2222

I have also activated port forward on sysctl

But the problems I experienced could not be solved by members of the Indonesian Linux forum
Terminal
Working On: LynaMC 3.0 ( SNAPSHOT )
Reply
#2
Moved from Hardware Forum to Support Forum.  Let's see whether our Guru Think Tank at post4vps can beat the Indonesian Linux Forum with coming up with a solution!  Tongue
[Image: 4ax8Kok.png]

Thank you to Post4VPS and VirMach for my super fast VPS 9!
- DH Blog
Reply
#3
(09-15-2019, 08:20 AM)chanalku91 Wrote:  Hello, I have a problem with port forwarding

I want to forward the connection from public zone port 22 to private zone port 2222 But I don't know why this command doesn't work

Terminal
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 22 -j DNAT --to 170.0.0.1:2222

I have also activated port forward on sysctl

But the problems I experienced could not be solved by members of the Indonesian Linux forum

You created the routing rule, that's good. But you are missing a very important thing: by default forwarding is set to block the traffic. You need to enable the traffic.

We can imagine the forwarding as two rules:
  • Forwarding rule to accept the traffic
  • Routing rule to redirect the traffic
So you should create a rule like this:
iptables -A FORWARD -i eth0 -p tcp –dport 22 -j ACCEPT
This command is based on your original command, using eth0 and tcp protocol

Can you tell me how to creates terminal style images like you? I know carbon but I am unable to get html code  Eh
Thanks to Post4VPS and VirMach for VPS 9 - Buffalo!
Reply
#4
"Public Zone" & "Private Zone" are two technical terms you will never hear or find if you are using just pure iptables. These terms are usually only used when you have a server with Redhat Enterprise Linux, CentOS or Fedora with firewalld. Just saying this to avoid confusion. You might not catch the relation now but maybe later you will. Especially important if as said you use one of the OSs I mentioned.

Anyway... A few questions to clear things up:
a) Does your server have a eth0 interface? OpenVZ for example doesn't have such interfaces. If you use KVM with newer OSs they usually have different interface names like enp0s1 and such.
b) 170.0.0.1 is what? Is that supposed to be a internal address? Is that assigned inside your server? Are you trying to forward to loopback? The loopback address is 127.0.0.1 but not 170.0.0.1. You most likely don't even own this IP address: https://www.ipaddress.com/ipv4/170.0.0.1
c) Which OS are you using and what kind of server do you have? Virtual? Dedicated? OpenVZ? KVM?
d) What is your current firewall configuration?
Kind regards
Hidden Refuge
Reply
#5
(09-15-2019, 02:10 PM)Hidden Refuge Wrote:  "Public Zone" & "Private Zone" are two technical terms you will never hear or find if you are using just pure iptables. These terms are usually only used when you have a server with Redhat Enterprise Linux, CentOS or Fedora with firewalld. Just saying this to avoid confusion. You might not catch the relation now but maybe later you will. Especially important if as said you use one of the OSs I mentioned.

Anyway... A few questions to clear things up:
a) Does your server have a eth0 interface? OpenVZ for example doesn't have such interfaces. If you use KVM with newer OSs they usually have different interface names like enp0s1 and such.
b) 170.0.0.1 is what? Is that supposed to be a internal address? Is that assigned inside your server? Are you trying to forward to loopback? The loopback address is 127.0.0.1 but not 170.0.0.1. You most likely don't even own this IP address: https://www.ipaddress.com/ipv4/170.0.0.1
c) Which OS are you using and what kind of server do you have? Virtual? Dedicated? OpenVZ? KVM?
d) What is your current firewall configuration?
1. My server has an eth0 interface
2. That typo I should write 127.0.0.1 
3. Ubuntu 18.04 (KVM)
4. Firewalls only allow incoming connections from ports 22 & 22022
Terminal
Working On: LynaMC 3.0 ( SNAPSHOT )
Reply
#6
(09-15-2019, 04:16 PM)chanalku91 Wrote:  1. My server has an eth0 interface
2. That typo I should write 127.0.0.1 
3. Ubuntu 18.04 (KVM)
4. Firewalls only allow incoming connections from ports 22 & 22022

I will add a screenshot of the firewall configuration on the VPS Maybe it will help


Attached Files Image(s)
       
Terminal
Working On: LynaMC 3.0 ( SNAPSHOT )
Reply
#7
(09-15-2019, 02:07 PM)LightDestory Wrote:  You created the routing rule, that's good. But you are missing a very important thing: by default forwarding is set to block the traffic. You need to enable the traffic.

We can imagine the forwarding as two rules:
  • Forwarding rule to accept the traffic
  • Routing rule to redirect the traffic
So you should create a rule like this:
iptables -A FORWARD -i eth0 -p tcp –dport 22 -j ACCEPT
This command is based on your original command, using eth0 and tcp protocol

Can you tell me how to creates terminal style images like you? I know carbon but I am unable to get html code  Eh
You only need to add the terminal code at the beginning and / terminal at the end! It is very easy !

 Yes, the command doesn't work properly
Terminal
Working On: LynaMC 3.0 ( SNAPSHOT )
Reply
#8
Your forward chain is set to DROP and has no rule that allows forwarding port 22 and 2222. Obviously this way it cannot work.
Kind regards
Hidden Refuge
Reply
#9
(09-16-2019, 06:14 AM)Hidden Refuge Wrote:  Your forward chain is set to DROP and has no rule that allows forwarding port 22 and 2222. Obviously this way it cannot work.

I also changed POLICY from FORWARD to ACCEPT but port forward still doesn't work? Is it because the target port 2222 closed at INTERFACE eth0 can affect Port Forwarding?
Terminal
Working On: LynaMC 3.0 ( SNAPSHOT )
Reply
#10
This thread can be closed, because Dwi Cahyo already provided a solution to my problem!
And thanks to @Hidden Refuge and @LightDestory for wanting to help me!
Terminal
Working On: LynaMC 3.0 ( SNAPSHOT )
Reply
 


Possibly Related Threads...
Thread Author Replies Views Last Post
  Problem installing some packages hamed 6 86 10-14-2019, 01:31 PM
Last Post: hamed
  iptables problem solving chanalku91 8 265 07-28-2019, 03:51 AM
Last Post: deanhills
  direct admin login problem hamed 6 206 07-21-2019, 10:21 AM
Last Post: hamed
  Some packages problem Debian Rehan 11 385 07-06-2019, 08:32 AM
Last Post: arsalahmed786
  Changing port Melvin 4 296 05-09-2019, 04:40 PM
Last Post: Hidden Refuge

Forum Jump:


Users browsing this thread: 1 Guest(s)

Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - SSDBlaze - VPSlices - Abc-Hosters - Hyper Expert - Shadow Hosting - Bladenode - HostDoc - Hostlease


About Post4VPS

Post4VPS is a forum/destiny where you can Delploy Your Free VPSs just by the Power of Posts.

We Provide VPSs of many locations like Germany,US,Canada,France,London,etc.

We also Provide VPSs of Both Linux and Windows OS.