LinuxQuestions.org
Visit Jeremy's Blog.
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-08-2024, 11:11 AM   #1
cwdztsd88
LQ Newbie
 
Registered: Feb 2024
Distribution: Pop_OS
Posts: 14

Rep: Reputation: 0
Question Redirect NAT Traffic of iptables to its source interface


How to redirect NAT traffic of iptables to its source interface?
I am working on wireguard vpn structure that is exotic:
for every client that will request vpn session my server will create a unique interface dedicated to one client. Design is simple: Server is 10.0.0.1, client is 10.0.0.2
But...

PostUp = iptables -A FORWARD -i intfc -j ACCEPT; iptables -t nat -A POSTROUTING -o ens5 -j MASQUERADE
PostDown = iptables -D FORWARD -i intfc -j ACCEPT; iptables -t nat -D POSTROUTING -o ens5 -j MASQUERADE

This sometimes causes connectivity issues if more than one client dedicated interfaces exists and that causes confusion on routing. How to get around of it?. My idea is making NAT redirect its returning traffic from internet to be routed to source interface but dont have experience in iptables at all.

Last edited by cwdztsd88; 04-08-2024 at 11:20 AM.
 
Old 04-09-2024, 08:13 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,143

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
iptables can send packets to a destination IP. Routing tables determine which interface that will be, not iptables. Have a look at iproute2 (policy based routing). https://lartc.org/howto/
 
Old 04-09-2024, 04:37 PM   #3
cwdztsd88
LQ Newbie
 
Registered: Feb 2024
Distribution: Pop_OS
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks, reading right now. Will report progress.
 
Old 04-12-2024, 03:45 PM   #4
cwdztsd88
LQ Newbie
 
Registered: Feb 2024
Distribution: Pop_OS
Posts: 14

Original Poster
Rep: Reputation: 0
Update:I feel alienated. I always thought fowarding and routing was same many years since i didn't felt to engineer networking stuff.

Last edited by cwdztsd88; 04-14-2024 at 07:53 AM. Reason: useless comment
 
Old 04-13-2024, 02:47 AM   #5
cwdztsd88
LQ Newbie
 
Registered: Feb 2024
Distribution: Pop_OS
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by smallpond View Post
iptables can send packets to a destination IP. Routing tables determine which interface that will be, not iptables. Have a look at iproute2 (policy based routing). https://lartc.org/howto/
Code:
sudo iptables -A PREROUTING -t mangle -p udp --dport 55210 -j MARK --set-mark 55210
sudo sh -c 'echo "200 wireguard.test" >> /etc/iproute2/rt_tables'
sudo ip rule add fwmark 55210 table wireguard.test
ip route add default via 10.0.0.2 dev wgutodf8 table wireguard.test
I did something like this but it didn't worked, where did i go wrong?
 
  


Reply

Tags
iptables



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
How can i redirect to other IP without "iptables -t NAT" ? postcd Linux - Security 16 08-01-2017 03:26 PM
NAT and NAT Server behind its own NAT(private network) zeusys Linux - Networking 1 06-08-2011 06:22 PM
iptables nat prerouting redirect issue - rhel 5.5 64-bit wischad Linux - Networking 1 11-12-2010 08:29 AM
[HELP] redirect traffic to spesific port based on Traffic Content using iptables summersgone Linux - Server 2 06-22-2009 11:26 AM

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

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