LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-06-2017, 08:40 PM   #1
Tonio-
LQ Newbie
 
Registered: May 2017
Posts: 24

Rep: Reputation: Disabled
DNAT Inside a LXC Container not working


Hello,

I have a LXC container (managed by Proxmox VE) that have a dedicated IP (IP Failover at OVH.net).
I want to set a DNAT rule to transfer the traffic from one port to another container. (in order to create a SSH connection in the other container that doesn't have a public IP)

Code:
-A PREROUTING -i eth0 -p tcp -m tcp --dport 2102 -j DNAT --to-destination 192.168.1.10:22 # My other Container IP


-A POSTROUTING -s 192.168.1.0/24 -o eth1 -j SNAT --to-source 1.1.1.1 # My public IP
-A POSTROUTING -s 192.168.1.0/24 -o eth1 -j MASQUERADE
But this is not working (I have an infinite delay when I try to connect through SSH.
The weird part is that if I set the same rule in the physical server, it's working.

Does anyone have an idea of what can I change to solve this issue ?

Thanks!
Tonio-
 
Old 07-07-2017, 01:34 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
First your 2 rules for POSTROUTING are going to be as problem. Only the first one is ever going to match making the second one useless. If I'm thinking right about what you are trying to do you are going to have to change your rules a bit. I'm assuming that you want traffic to 192.168.1.10 to be natted to your private ip address of 192.168.10.x that you have set on that interface. Give this a try:

Code:
-A POSTROUTING -d 192.168.1.10 -o eth1 -j MASQUERADE
-A POSTROUTING -o eth1 -j SNAT --to-source 1.1.1.1
If the packet leaving eth0 is destine for 192.168.1.10 the packet will be MASQed.
Else SNAT all traffic leaving eth0 to the public IP.

IPTABLES matches top down and executes the first exact match. If all traffic leaving the interface is going to have a source of 192.168.1.x then you really do not need to use the '-s 192.168.1.0/24'
 
1 members found this post helpful.
Old 07-07-2017, 07:14 PM   #3
Tonio-
LQ Newbie
 
Registered: May 2017
Posts: 24

Original Poster
Rep: Reputation: Disabled
Oh interesting, I'm improving my understanding of iptables so.

Thank you very much!

Tonio-
 
Old 07-10-2017, 11:58 AM   #4
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
You are welcome.
 
  


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
LXC Container: sound Not working charlie101 Linux - Virtualization and Cloud 11 04-14-2020 01:15 AM
How to check for mounted filesystems inside a lxc container cianfa72 Linux - Containers 11 05-31-2017 03:21 AM
LXer: Inside the Open Container Project: How Docker plans to unite the container market LXer Syndicated Linux News 0 06-23-2015 04:30 AM
[SOLVED] Outputting X display from inside an LXC Container charlie101 Linux - Virtualization and Cloud 1 02-04-2013 09:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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