LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 02-29-2016, 03:13 PM   #1
hackingNerd
LQ Newbie
 
Registered: Feb 2016
Posts: 2

Rep: Reputation: Disabled
Iptable Port Forwarding is not working for Host Only Network


Host OS Ubuntu with live(public) IP address 1.2.3.4 .

And a Ubuntu VM running in Virtual Box with Host Only and NAT network configuration. Configuration of both network cards are according to this ttp://christophermaier.name/blog/201...ith-virtualbox.

Now my VM have IP address 192.168.56.101.
I successfully SSH my VM from host. But when i move forward, I implement IPTables rule to forward traffic from host to VM. It is not working. I have enabled IP forwarding at host with #sysctl net.ipv4.ip_forward=1, and added #iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to-destination 192.168.56.101:2222 to /etc/iptables/rules.v4.

Now when I ssh my VM from external network with IP address 3.3.3.3 with command #ssh vmusername@1.2.3.4 -p 2222, it stuck. No output. also No logs on my host 1.2.3.4 and VM. I have also added port 2222 in ssh config (/etc/ssh/sshd_config) of my VM.

Host IPTables rules (/etc/iptables/rules.v4)


xxxxx@xxxxx:~$ iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
DROP all -- anywhere anywhere ctstate INVALID
UDP udp -- anywhere anywhere ctstate NEW
TCP tcp -- anywhere anywhere tcp flags:FIN,SYN,RST,ACK/SYN ctstate NEW
ICMP icmp -- anywhere anywhere ctstate NEW
REJECT udp -- anywhere anywhere reject-with icmp-port-unreachable
REJECT tcp -- anywhere anywhere reject-with tcp-reset
REJECT all -- anywhere anywhere reject-with icmp-proto-unreachable

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain ICMP (1 references)
target prot opt source destination

Chain TCP (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh

Chain UDP (1 references)
target prot opt source destination

Use Case: I have deployed SSH Honeypots in my VM. Any one who will try to SSH my Live IP 1.2.3.4 at port 2222, will be forwarded to SSH honeypot. In honeypot VM all SSH sessions are logged. So in logs I need the real IP of attacker(3.3.3.3).

I have also asked this question on some other forums.

http://www.cnet.com/forums/discussio...14567796487229

http://unix.stackexchange.com/questi...t-am-i-doing-w
 
Old 02-29-2016, 05:54 PM   #2
pingu_penguin
Member
 
Registered: Aug 2004
Location: pune
Distribution: Slackware
Posts: 355

Rep: Reputation: 60
try this on the ubuntu live host (1.2.3.4) :

#iptables -t nat -A POSTROUTING -o <interface where ssh connections come in> -j MASQUERADE
 
Old 02-29-2016, 07:14 PM   #3
pingu_penguin
Member
 
Registered: Aug 2004
Location: pune
Distribution: Slackware
Posts: 355

Rep: Reputation: 60
My sincere apologies for the confusion.
That above line wont work :S
 
Old 03-01-2016, 01:35 PM   #4
hackingNerd
LQ Newbie
 
Registered: Feb 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
@pingu_penguin

I have no need of post routing. I have setup NAT for my VM to communicate back to world. I only need to make my Host able to forward packets to VM. Thanks for your answer.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] SSH port forwarding: connection closed by remote host m_yates Linux - Networking 4 05-16-2014 09:24 AM
External port forwarding to an internal host antken Linux - Networking 3 12-17-2006 09:43 AM
http port forwarding: outside network not working sharathg786 Linux - Networking 2 08-12-2006 11:37 PM
port forwarding using IPTABLE ...( Help) ad2005 Linux - Networking 5 03-15-2006 10:56 PM
IPTable Problems (Port Forwarding)... Arch3Angel Linux - Security 3 12-04-2004 04:56 PM

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

All times are GMT -5. The time now is 12:14 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