LinuxQuestions.org
Help answer threads with 0 replies.
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 06-29-2015, 01:30 PM   #1
theredcomputer
LQ Newbie
 
Registered: Jun 2015
Location: Madison, WI
Posts: 2

Rep: Reputation: Disabled
Question iptables - SSH port forwarding to static-IP VM in OpenWRT


I have an embedded computer running OpenWRT. This implementation has a specialized bit of software which allows for the creation of a virtual machine. This virtual machine is always able to be ssh'ed to from the OpenWRT command line.

Now, in an effort to make maintenance of the VM easier without completely destroying the instance, it would be beneficial if we were able to ssh to the embedded computer on a specific port which would port-forward to the VM. The VM has a static IP address of 1.2.3.4. The embedded computer has a hostname, called "tree", which maps to a static IP address in the range of 11.22.0.1 to 11.22.1.255. The embedded computer has an OpenVPN tunnel which guarantees ssh'ing to it from my PC.

Visually, I want to cut down this:

Code:
----------                      ------------------------------------------
|        |                      |                                        |
|        |  $ ssh root@tree     |           $ ssh root@1.2.3.4    ------ |
|  My PC |--------------------->| OpenWRT ----------------------> | VM | |
|        |                      |                                 ------ |
|        |                      |                                        |
----------                      ------------------------------------------
to this:
Code:
----------                              ------
|        |  $ ssh root@tree -p 5678     |    |
|  My PC |----------------------------->| VM |
|        |                              |    |
----------                              ------
Using iptables to configure rules seems to be the best option to accomplish this. Here are the commands I have used in the OpenWRT command line (note: iface0 is the VPN tunnel):

Code:
iptables -A PREROUTING -t nat -i iface0 -p tcp -m tcp --dport 5678 -j DNAT --to-destination 1.2.3.4:22
iptables -A FORWARD -i iface0 -s 11.22.0.0/24 -d 1.2.3.4 -j ACCEPT
iptables -A FORWARD -o iface0 -s 1.2.3.4 -d 11.22.0.0/24 -j ACCEPT
However, when performing
Code:
$ ssh root@tree -p 5678
, the connection times out. It's not flat-out rejected as other ports are (such as 5679), so something seems to be happening, but I'm not sure why this isn't getting through.

Any help would be very much appreciated!

Last edited by theredcomputer; 06-29-2015 at 02:11 PM. Reason: Forgot the '-t nat' option from the first iptables command; third iptables command should be '-o', not '-i'
 
Old 06-30-2015, 12:31 PM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
Timeout suggest that he connection is being dropped by another rule or a firewall rule on the VM itself.

You should look into making your rules STATEFULL.
 
Old 06-30-2015, 01:15 PM   #3
theredcomputer
LQ Newbie
 
Registered: Jun 2015
Location: Madison, WI
Posts: 2

Original Poster
Rep: Reputation: Disabled
lazydog,

Thanks for the reply. I managed to figure it out! What I did was edited
Code:
/etc/config/firewall
and added the following text:

Code:
config zone
    option name 'vm_zone'
    option output 'ACCEPT'
    option input 'ACCEPT'
    option forward 'REJECT'
    option masq '1'
    option network 'vm_zone'

config forwarding
    option src 'vm_zone'
    option dest 'wan'
Turns out the VM didn't live in a normal zone. However, the three iptables commands I ran above were all necessary.

Again, thanks!
 
  


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
[SOLVED] IPtables : ssh port forwarding one port to another port issue routers Linux - Networking 7 08-07-2018 08:41 AM
Port Forwarding with iptables or ssh linker3000 Linux - Software 11 07-07-2008 08:41 AM
IPCHAINS port forwarding and IPTABLES port forwarding ediestajr Linux - Networking 26 01-14-2007 07:35 PM
Iptables Forwarding Problem -OpenWRT stlpcsolutions Linux - Networking 1 11-30-2006 02:23 PM
SSH Port Forwarding with IPTables & DNAT MercurioBlue Linux - Networking 2 08-24-2006 11:17 PM

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

All times are GMT -5. The time now is 02:30 PM.

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