-1

i am quite new in this area, so in case you need clarification please ask me more as there is a chance for me not to describe correctly the problem.

Let's asume i have this scenario :

  • Public ip 5.2.162.266/21 and gateway 5.2.160.1 on gateway named : enp4s1
  • Private ip 192.168.0.100 and gateway 192.168.0.1 on gateway named : enp2s0

here i have the details on enp2s0 :

cat ifcfg-enp2s0
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="no"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
NAME="enp2s0"
DEVICE="enp2s0"
ONBOOT="yes"
DNS1="8.8.8.8"
DNS2="4.2.2.4"
IPADDR=192.168.0.100
PREFIX=24
GATEWAY=192.168.0.1
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_PRIVACY=no   

and for enp4s1 :

cat ifcfg-enp4s1
TYPE=Ethernet
BOOTPROTO=static
DNS1=8.8.8.8
DNS2=4.2.2.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME=enp4s1
ONBOOT=yes
MTU=1440
IPADDR=5.2.162.266
PREFIX=21
GATEWAY=5.2.160.1
DEVICE="enp4s1"   

( i would like to have separate routes for them and not to use as DEFROUTE enp4s1 )

I don't need a default gateway. I need requests from public ip to be answered by it's gateway and local requests to be resolved locally.

How can i achieve this type of routing?

Thank you helping buddy!

Mr'Black
  • 274
  • 1
  • 6
  • 19

1 Answers1

0

If you have just 192.168.0.0/24 and no more private networks, simply remove GATEWAY=192.168.0.1 , DNS1="8.8.8.8" and DNS2="4.2.2.4" lines from enp2s0 configurations file. If you do that, your default GW will be 5.2.160.1 and all requests from your private network 192.168.0.0/24 will be answered by enp2s0 interface.

If you need to add more local private networks, you need to add a route for every network. For example if you also have 192.168.1.0/24 you need to run this command in order to add a route for this network ip route add 192.168.1.0/24 via 192.168.0.1 dev enp2s0 .

Do not forget to restart network daemon after the changes systemctl restart network .

IAmAliYousefi
  • 1,132
  • 3
  • 21
  • 33