LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   How to provide a route to a subnet? (https://www.linuxquestions.org/questions/linux-server-73/how-to-provide-a-route-to-a-subnet-4175642718/)

vinalencc1986 11-20-2018 08:32 AM

How to provide a route to a subnet?
 
Hello, guys! How are you?

I'd like to ask for help with servers and networking.
In my network, I have 2 blocks: 192.168.1.0/24 and 192.168.2.0/24.
The 1st network is OK: it's connected to the Internet and the servers/clients have access to "anything" in the web. But, I'm facing problems with my 2nd network.
I have 2 servers (master/slave) that connect the 1st network with the 2nd one, but I can't get a default route/gateway from 192.168.1.0/24 to 192.168.2.0/24.

For both servers, here is my network interface's setting:
Code:

auto lo
iface lo inet loopback

# First Network
auto enp0s3
iface enp0s3 inet static
    network 192.168.1.0
    gateway 192.168.1.1
    broadcast 192.168.1.255
    netmask 255.255.255.0
    address 192.168.1.181  # Secondary server's address is 192.168.1.182

# Second network
auto enp0s8
iface enp0s8 inet static
    network 192.168.2.0
    #gateway 192.168.2.1
    broadcast 192.168.2.255
    netmask 255.255.255.0
    address 192.168.2.1  # Secondary server's address is 192.168.2.2

Here is my Primary DHCP server's config (the Secondary DHCP server is basicly the same thing):
Code:

authoritative;
ddns-update-style interim;
option domain-name "mynetwork.local";
option domain-name-servers ns1.mynetwork.local, ns2.mynetwork.local, 192.168.2.1, 192.168.2.2;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;

failover peer "DHCP-FAILOVER" {
    primary;
    address 192.168.2.1;
    port 647;

    peer address 192.168.2.2;
    peer port 647;

    max-response-delay 30;
    max-unacked-updates 10;

    load balance max seconds 3;
    mclt 1800;
    split 128;
}

subnet 192.168.2.0 netmask 255.255.255.0 {
    option routers 192.168.2.1, 192.168.2.2;
    option subnet-mask 255.255.255.0;
    option domain-name "mynetwork.local";
    option domain-name-servers 192.168.2.1, 192.168.2.2;

    option netbios-dd-server 192.168.2.1, 192.168.2.2;
    option netbios-name-servers 192.168.2.1, 192.168.2.2;
    option netbios-node-type 8;

    option nis-domain "mynetwork.local";
    option nis-servers 192.168.2.1, 192.168.2.2;
    option nisplus-domain "mynetwork.local";
    option nisplus-servers 192.168.2.1, 192.168.2.2;

    option ntp-servers 192.168.2.1, 192.168.2.2;

    option time-offset -18000;

    pool {
        failover peer "DHCP-FAILOVER";
        range 192.168.2.3 192.168.2.254;
    }
}

And I have this firewall script:
Code:

#!/bin/bash

modprobe iptable_nat
modprobe iptable_filter
modprobe iptable_mangle
modprobe ipt_MASQUERADE
modprobe ip_tables
modprobe nf_conntrack
modprobe nf_conntrack_ipv4
modprobe nf_nat
modprobe nf_tables
modprobe nf_tables_ipv4
modprobe nft_masq
modprobe nft_masq_ipv4
modprobe nft_nat
modprobe nft_redir
modprobe nft_redir_ipv4

iptables -t filter -F
iptables -t mangle -F
iptables -t nat -F

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

EXTERNAL_NETWORK=192.168.1.0 # My 1st network
EXTERNAL_INTERFACE=enp0s3    # Interface connected to 192.168.1.0/24
INTERNAL_NETWORK=192.168.2.0 # My 2nd network
INTERNAL_INTERFACE=enp0s8    # Interface connected to 192.168.2.0/24

# Getting hostname to set the variable "SRV_IP_ADDR"
[[ $(hostname) = master ]] && SRV_IP_ADDR=192.168.2.1 || SRV_IP_ADDR=192.168.2.2

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o $EXTERNAL_INTERFACE -j MASQUERADE

iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -i $EXTERNAL_INTERFACE -j ACCEPT  # Interface enp0s3
iptables -A OUTPUT -o $EXTERNAL_INTERFACE -j ACCEPT
iptables -A FORWARD -i $EXTERNAL_INTERFACE -j ACCEPT

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

# Accepting SSH connections
iptables -A INPUT -i $EXTERNAL_INTERFACE -p tcp --dport 1024 -j ACCEPT
iptables -A INPUT -s $EXTERNAL_NETWORK/24 -p tcp --dport 1024 -j ACCEPT

# If a package goes to the internet (external network), it must return to the internal network
iptables -A FORWARD -d $INTERNAL_NETWORK/24 -p tcp -j ACCEPT
iptables -A FORWARD -s $INTERNAL_NETWORK/24 -p tcp -j ACCEPT

# Accepting WWW, WWWS, DHCP and DNS connections/queries
iptables -A FORWARD -s $SRV_IP_ADDR -m multiport -p tcp --dport 80,443 -j ACCEPT
iptables -A FORWARD -d $SRV_IP_ADDR -m multiport -p tcp --sport 80,443 -j ACCEPT
# These 2 lines bellow are for TCP
iptables -A FORWARD -s $INTERNAL_NETWORK/24 -m multiport -p tcp --dport 53,67 -j ACCEPT
iptables -A FORWARD -d $INTERNAL_NETWORK/24 -m multiport -p tcp --sport 53,67 -j ACCEPT
# These 2 lines bellow are for UDP
iptables -A FORWARD -s $INTERNAL_NETWORK/24 -m multiport -p udp --dport 53,67 -j ACCEPT
iptables -A FORWARD -d $INTERNAL_NETWORK/24 -m multiport -p udp --sport 53,67 -j ACCEPT

What can I do to add a default route to my 2nd network?
I am asking about default route, because I can't install Debian Linux into clients located on 192.168.2.0/24 (It says that are no default route and it fails to set a mirror, because it seems to be a unreachable network). Or in the Windows clients, I need to set the 1st network DNS/gateway (192.168.1.1) to have access to internet.
What can I do?
Thank you for your attention.

ferrari 11-21-2018 02:01 AM

Show us the current routing table
Code:

ip route

vinalencc1986 11-21-2018 08:39 AM

Hello, @ferrari

Here is my route table (server = master / basically the same for slave):

default via 192.168.1.1 dev enp0s3 onlink
169.254.0.0/16 dev enp0s3 scope link metric 1000
192.168.1.0/24 dev enp0s3 proto kernel scope link src 192.168.1.181
192.168.2.0/24 dev enp0s8 proto kernel scope link src 192.168.2.1

ferrari 11-21-2018 11:51 AM

Is this a valid representation of your network?

Internet----GW router---<192.168.1.x/24>----Server----<192.168.2.x/24>----Hosts on 192.168.2.x network

If so, is the issue about hosts on your 192.168.2.x network that can't reach the internet? They will need 192.168.2.1 set as their gateway address.

vinalencc1986 11-22-2018 08:16 AM

Yes, this is my network's representation.
Okay, thanks! I will check it out.
By the way, can you recommend me a tutorial for this, please?


All times are GMT -5. The time now is 11:43 AM.