LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to route to home network and global network (https://www.linuxquestions.org/questions/linux-networking-3/how-to-route-to-home-network-and-global-network-4175703397/)

ballsystemlord 11-10-2021 08:50 PM

How to route to home network and global network
 
Hello,
This problem has probably been asked and answered 1,000 times already, I just can't find the right search terms. So please just point me in the right direction. I will RTFM.

I wanted to create an intranet (home net), and have a second connection go to the internet (global net). I can setup routing for the local router to assign addresses on the intranet just fine.
What I have trouble with is telling Linux to send packets for other addresses than 192.168.1.XXX to the global network interface, and vice versa. It seems Linux just chooses one or the other interface and puts every packet onto it assuming they will reach their destination -- when they will not.
I also need to know how, if one link goes down, to make Linux NOT send all the packets for that interface out the other one. Linux appears to assume that the links are a redundancy measure by default, not 2 different networks.

Thanks!

michaelk 11-10-2021 09:20 PM

From your post it appears you want to build a router. A quick search here and the Internet will find many guides.

Basically to route traffic from one interface to another you need to enable ip_forward which is a kernel parameter i.e. echo 1 > /proc/sys/net/ipv4/ip_forward and can be set permanently in your sysctl.conf. There is a similar configuration for IPV6 if needed. Using masquerade firewall rules you can setup a NAT router.

frankbell 11-10-2021 09:41 PM

You might be able to do this with iptables. A web search for "iptables route network packets" turns up a number of articles that might be helpful.

This one might be a good place to start: https://serverfault.com/questions/34...ific-interface

Full Disclosure: I've never done anything like this myself.

michaelk 11-10-2021 09:46 PM

I forgot to mention for DHCP clients your DHCP server also needs to set gateway IP address which is the LAN IP address and DNS name server options.

ballsystemlord 11-11-2021 07:17 PM

Quote:

Originally Posted by frankbell (Post 6300218)
You might be able to do this with iptables. A web search for "iptables route network packets" turns up a number of articles that might be helpful.

This one might be a good place to start: https://serverfault.com/questions/34...ific-interface

Full Disclosure: I've never done anything like this myself.

That looks like a great place to start. Thanks! I'll try to work from that and repost my success/failure.

To be clear, I'm not trying to create a nat router -- I intend to in the future, but I can find docs on that pretty easily.

Turbocapitalist 11-11-2021 10:26 PM

Quote:

Originally Posted by ballsystemlord (Post 6300526)
That looks like a great place to start.

If you are just starting out then it might be a better idea to begin with NFTables instead. First that's where all the development is currently happening. Second, NFTables is planned to replace IPTables sometime, though the latter has a tragicomically long tail due to all the easily found but outdated material out there on the web.

For NFTables, look at their Wiki:

https://wiki.nftables.org/

https://wiki.nftables.org/wiki-nftab..._in_10_minutes

ballsystemlord 11-12-2021 06:34 PM

Quote:

Originally Posted by Turbocapitalist (Post 6300556)
If you are just starting out then it might be a better idea to begin with NFTables instead.
<snip>

Now that I do some searching, if I'm going to try and leverage NFTables, why not eBPF?

https://ebpf.io/what-is-ebpf/
https://www.kernel.org/doc/html/latest/bpf/index.html

ballsystemlord 11-12-2021 06:35 PM

Granted, there's not going to be any examples of how to get eBPF to do what I want, but then NFTables isn't much better according to the above.


All times are GMT -5. The time now is 04:30 AM.