LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-20-2018, 08:32 AM   #1
vinalencc1986
LQ Newbie
 
Registered: Nov 2018
Location: Brazil
Distribution: Debian
Posts: 3

Rep: Reputation: Disabled
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.
 
Old 11-21-2018, 02:01 AM   #2
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,779

Rep: Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139
Show us the current routing table
Code:
ip route
 
Old 11-21-2018, 08:39 AM   #3
vinalencc1986
LQ Newbie
 
Registered: Nov 2018
Location: Brazil
Distribution: Debian
Posts: 3

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-21-2018, 11:51 AM   #4
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,779

Rep: Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139Reputation: 1139
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.
 
Old 11-22-2018, 08:16 AM   #5
vinalencc1986
LQ Newbie
 
Registered: Nov 2018
Location: Brazil
Distribution: Debian
Posts: 3

Original Poster
Rep: Reputation: Disabled
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?

Last edited by vinalencc1986; 11-22-2018 at 08:18 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Packet going out of wrong interface due to OS adding cache route - OS trying to route through default route msr1981 Linux - Networking 2 10-11-2017 02:58 PM
Packet going out of wrong interface due to OS adding cache route - OS trying to route through default route msr1981 Red Hat 1 10-09-2017 05:45 AM
Route a /24 public subnet to another /24 public subnet pciccone Linux - Networking 9 11-07-2014 07:52 PM
I am not able to add a new route to my route table using route command prashanth s j Linux - Networking 2 09-03-2005 04:34 AM
Route to subnet exists but I get "Network unreachable" when adding default route fciuffani Linux - Networking 4 08-18-2004 02:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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