Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lan client Route from ip address and port #40

Open
Salvora opened this issue Oct 23, 2020 · 5 comments
Open

Lan client Route from ip address and port #40

Salvora opened this issue Oct 23, 2020 · 5 comments

Comments

@Salvora
Copy link

Salvora commented Oct 23, 2020

Love your script so far.
I know this can be done using iptables and manually arranging things but it is difficult this way so I am just curious;
Is there a way to specify the lan ip and port for routing using x3m?

I mean:
Route to VPNX, If a connection comes from Lan Client X with port XXXX?

I have a server that runs some specific applications using predefined ports. I don't want my whole server to be on VPN connections. Just those specific applications.

@Xentrk
Copy link
Owner

Xentrk commented Oct 24, 2020

I don't have the feature for port routing at the moment. I will look into it. Since you are using x3mRouting, you can use the instructions https://github.com/RMerl/asuswrt-merlin.ng/wiki/Policy-based-Port-routing-(manual-method) for port routing and place the iptables command in /jffs/scripts/x3mRouting/vpnclient1-route-up and /jffs/scripts/x3mRouting/vpnclient1-route-pre-down

vpnclient1-route-up (have a -D entry to prevent duplicates before creating the rule)
iptables -t mangle -D PREROUTING -i br0 -m iprange --src-range 192.168.1.99 -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x2000/0x2000 2> /dev/null
iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range 192.168.1.99 -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x2000/0x2000

vpnclient1-route-pre-down
iptables -t mangle -D PREROUTING -i br0 -m iprange --src-range 192.168.1.99 -p tcp -m multiport --dport 80,443 -j MARK --set-mark 0x2000/0x2000 2> /dev/null

@Xentrk
Copy link
Owner

Xentrk commented Oct 24, 2020

The above assumes you have a rule already created using x3mRouting that uses the VPN iface so the fwmark gets created.

@Salvora
Copy link
Author

Salvora commented Oct 24, 2020

Hmm,
I understand. I will test this. It is great that you can integrate this feature by using /jffs/scripts/x3mRouting/vpnclient1-route-up and /jffs/scripts/x3mRouting/vpnclient1-route-pre-down instead of creating a second vpn client.
Thanks for the assistance.
It would be even better if a future update of x3m integrates this natively instead of manually entering commands.
Anyway, thanks for the help again.
One question though:
I use dnsmasq method for x3m
x3mRouting ALL 1 ILIST dnsmasq_file=/jffs/scripts/x3mRouting/Hosts
"Hosts" is the file that contains top level domain names. This works globally for every client. The whole network uses VPN for the domains in the "Hosts" file.
If I add this port routing method on top of my current settings, will it break anything?
I mean:
dnsmasq method globally + port routing for a specific client with port that will ignore the domain names and use VPN everywhere

@Salvora
Copy link
Author

Salvora commented Oct 31, 2020

A little bit clarification for my previous question:
If I add these rules to
vpnclient1-route-up
and
vpnclient1-route-pre-down

will it work together with my preexisting rules?

Currently my vpnclient1-route-up looks is:
#!/bin/sh
iptables -t mangle -D PREROUTING -i br0 -m set --match-set GULIBU dst -j MARK --set-mark 0x1000/0x1000 2>/dev/null
iptables -t mangle -A PREROUTING -i br0 -m set --match-set GULIBU dst -j MARK --set-mark 0x1000/0x1000

and vpnclient1-route-pre-down is:
#!/bin/sh
iptables -t mangle -D PREROUTING -i br0 -m set --match-set GULIBU dst -j MARK --set-mark 0x1000/0x1000 2>/dev/null

so if I add this newly created 2 lines
vpnclient1-route-up is:

#!/bin/sh
iptables -t mangle -D PREROUTING -i br0 -m set --match-set GULIBU dst -j MARK --set-mark 0x1000/0x1000 2>/dev/null
iptables -t mangle -A PREROUTING -i br0 -m set --match-set GULIBU dst -j MARK --set-mark 0x1000/0x1000
iptables -t mangle -D PREROUTING -i br0 -m iprange --src-range 192.168.1.41 -p tcp -m multiport --dport 54333,6881 -j MARK --set-mark 0x1000/0x1000 2> /dev/null
iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range 192.168.1.41 -p tcp -m multiport --dport 54333,6881 -j MARK --set-mark 0x1000/0x1000

vpnclient1-route-pre-down is:

#!/bin/sh
iptables -t mangle -D PREROUTING -i br0 -m set --match-set GULIBU dst -j MARK --set-mark 0x1000/0x1000 2>/dev/null
iptables -t mangle -D PREROUTING -i br0 -m iprange --src-range 192.168.1.41 -p tcp -m multiport --dport 54333,6881 -j MARK --set-mark 0x1000/0x1000 2> /dev/null

Will it break anything?

@Xentrk
Copy link
Owner

Xentrk commented Nov 18, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants