You are not logged in.
Hi!
I'm wondering how I can set up dual network.
I have two networks. One connects to the internet, and is assigned with an IP that can be accessed by the internet. The other network is internal.
I'm wondering how I can set up the system so that it uses the first network most of the time, except when accessing the internal network?
Thank you!
Last edited by Wen (2016-11-02 17:06:02)
Offline
Are you trying to set up a machine as a router? Then this article might help: https://wiki.archlinux.org/index.php/Internet_sharing
If you don't need that, then nothing special is required: you assign your LAN-facing NIC (network interface card) an IP address (either dynamically or statically), and the kernel will set up routes automatically. Just verify that the default route goes through the internet-facing NIC.
Example
You assign your LAN-facing NIC the IP address 192.168.1.10 with a network mask of 255.255.255.0 (short notation: /24).
The kernel will set up the routing rules such that all packets with a destination IP address in the 192.168.1.0/24 subnet (range: 192.168.1.0 (?) - 192.168.1.255) will be routed through that NIC.
If a packet's destination IP address is not in that subnet's range (and matches no other routing rules, if there are any), the default route is chosen, which should go through the internet-facing NIC.
EDIT
Here's an example routing table for my laptop:
default via 192.168.1.1 dev wlp3s0 proto dhcp src 192.168.1.121 metric 1024
172.16.110.0/24 dev qemu0 proto kernel scope link src 172.16.110.1 linkdown
192.168.1.0/24 dev wlp3s0 proto kernel scope link src 192.168.1.121
192.168.1.1 dev wlp3s0 proto dhcp scope link src 192.168.1.121 metric 1024
Here, I have been assigned 192.168.1.121/24 by the DHCP server on my WiFi NIC (wlp3s0), so packets with a destination IP address in 192.168.1.0/24 will be routed through wlp3s0.
Then, I have additionally assigned 172.16.110.1/24 to my VM-facing network bridge (qemu0), so packets with a destination IP address in 172.16.110.0/24 will be routed through qemu0.
Finally, there is a default route that tells packets that do not match any of those rules to go through wlp3s0 - which makes sense, because the internet is there
Last edited by ayekat (2016-11-01 10:45:23)
Offline
Thank you ayekat!
No, I do not intend to set up the machine as a router.
The machine has two network cards: wlp3s0 and eno1.
wlp3s0 is the wireless network adapter. I run wpa_supplicant to set up the network first, and then use dhclient to get an IP. This is network connects to the Internet.
eno1 is the wired network adapter. I run dhclient to get an IP. This connects to an internal network.
My plan is to set up an SSH server, so that I can ssh to this computer via wlp3s0, and then from there access the internal network through eno1.
I don't understand your routine table. Where do I edit it?
Thank you!
Offline
Just to clarify: the internal network (on eno1) is not the same as the one on wlp3s0?
Where do I edit it?
The routing table can be displayed with
ip route
If you use dhclient for both the wired and wireless network interface, it is possible that two default routes are set, in which case you will need to remove one of them.
See also https://wiki.archlinux.org/index.php/Ne … assignment
Offline
Thank you!
Good question! No, they are on different networks.
Offline
Hi again,
Thanks to you, I have managed to get part of network setup:
default via 193.150.115.1 dev wlp3s0
10.1.1.0/24 dev eno1 proto kernel scope link src 10.1.1.46
193.150.115.0/22 dev wlp3s0 proto kernel scope link src 193.150.115.133
However, I'm not able to reach computers that are part of the internal network, for example, another computer with an IP address of 10.1.8.22.
I tried to add the following line:
# ip route add 10.1.8.0/24 dev eno1 proto kernel scope link src 10.1.1.46
However, this does not help. Could you help?
Offline
default via 193.150.115.1 dev wlp3s0 10.1.1.0/24 dev eno1 proto kernel scope link src 10.1.1.46 193.150.115.0/22 dev wlp3s0 proto kernel scope link src 193.150.115.133
However, I'm not able to reach computers that are part of the internal network, for example, another computer with an IP address of 10.1.8.22.
If your machine gets assigned 10.1.1.46/24, this means that it is part of the 10.1.1.0/24 network (range: 10.1.1.0 - 10.1.1.255).
The machine at 10.1.8.22 is outside that range and thus in another network. This leaves me wondering: are there multiple networks? Or how did the machine behind 10.1.8.22 obtain its IP address?
I tried to add the following line:
# ip route add 10.1.8.0/24 dev eno1 proto kernel scope link src 10.1.1.46
However, this does not help.
Perhaps your router's firewall prevents packets from crossing networks like that... honestly, I have never tried to set up a route where the source address is not part of that subnet, so I can't really tell you whether it's supposed to work or not.
Offline
Thank you bud.
I do not know the configuration behind. I can access 10.1.8.22 when I set the default to be 10.1.1.1, strangely.
Offline
Hey. I'm very happy to tell you that I have found a solution, which is so easy that I couldn't believe it:
ip route add 10.1.8.0/24 via 10.1.1.1
Offline
And thanks a lot for the journey!
Offline
Ah, now I get it - there are multiple networks, and the router (10.1.1.1) acts as the gateway (between 10.1.1.0/24 and 10.1.8.0/24), and if you send packets to the 10.1.8.0/24 network through that router, they follow the right path.
Nice to hear it worked out
Offline
Yep! :-D
Offline