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-10-2022, 11:53 PM   #1
tkalfaoglu
Member
 
Registered: Oct 2003
Location: Izmir, Turkey
Distribution: Fedora Core 10
Posts: 68

Rep: Reputation: 15
Port based routing


Hello. I have a dilemma. I would like most ports to go over my VPN connection, and one port to go over directly. the gateways are 10.8.0.5 and 192.168.1.60 respectively.

I so far did this:
Code:
# more /etc/rt_tables 
(...)
1       vpn
2       bitnet
and wrote a script that has:

Code:
iptables -A PREROUTING -t mangle -i enp6s0 -p tcp --dport 30890  -j MARK --set-mark 2
iptables -A PREROUTING -t mangle -i enp6s0 -p udp  --dport 30890 -j MARK --set-mark 2
ip route add 10.8.0.5 dev tun0
ip route add 192.168.1.60 dev enp6s0
ip route add default via 10.8.0.5 dev tun0       table vpn
ip route add default via 192.168.1.60 dev enp6s0 table bitnet
ip rule add from all fwmark 1 table vpn
ip rule add from all fwmark 2 table bitnet
I am missing something. After running it nothing can be pinged or reached, even the gateways do not answer to pings. I feel I need to add something to table bitnet so that it's used for "everything else" but how do I formulate that?
 
Old 06-11-2022, 08:27 PM   #2
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,859

Rep: Reputation: 1151Reputation: 1151Reputation: 1151Reputation: 1151Reputation: 1151Reputation: 1151Reputation: 1151Reputation: 1151Reputation: 1151
You currently have
Code:
iptables -A PREROUTING -t mangle -i enp6s0 -p tcp --dport 30890  -j MARK --set-mark 2
iptables -A PREROUTING -t mangle -i enp6s0 -p udp  --dport 30890 -j MARK --set-mark 2
For outgoing packets use the OUTPUT chain (PREROUTING is for incoming packets)...
Code:
iptables -A OUTPUT -t mangle -i enp6s0 -p tcp --dport 30890  -j MARK --set-mark 2
iptables -A OUTPUT -t mangle -i enp6s0 -p udp  --dport 30890 -j MARK --set-mark 2
Useful reference:
https://stackunderflow.dev/p/iptables-for-routing/

You should only have one default gateway so remove
Code:
ip route add default via 192.168.1.60 dev enp6s0 table bitnet
and use
Code:
ip route add 0.0.0.0/1 via 192.168.1.60 dev enp6s0 table bitnet

Last edited by ferrari; 06-11-2022 at 08:33 PM.
 
  


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
routing protocol based on based geo -cast routing in vehicular ad hoc netwok Adaramola ojo jayeola Linux - Wireless Networking 1 06-02-2016 08:53 AM
Routing based on destination port rvo Linux - Networking 9 01-11-2011 09:48 AM
Advanced routing based on outgoing port tenko20xx Linux - Networking 2 02-14-2009 11:18 AM
Port based routing neos Linux - Networking 1 09-21-2005 01:15 PM

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

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