0

I am creating a test environment. In Which i have a production network,isolated network and linux machine. In Linux machine having 2 NICs, one NIC is connected to production network environment then assigned a IP and another one is Isolated network.

PROD-------(eth0)[LINUXMACHINE](eth1)-----ISOALTED NETWORK 

In the above representation, after configuring one NIC(eth0) , i can able to ping from production network machines to Linux Machine. Then am configured the eth1 to default gateway of the isolated network. After enabling eth1, can able to ping from and to Linux machine to Isolated env. Now I cant able to ping from Prod to Linux machine.If i am disabling the eth1 means, it will works otherwise it wont.

I am newbee to networking. I don't know exactly where is the issue and what i did wrong. I have enabled the following

IP Forwarding, MASQUERADE and some iptables rules

Anyone can suggest me a good way to make this work.

Thanks in advance

edited

ifconfig

eth0      Link encap:Ethernet  HWaddr 00:50:56:8f:68:e7  
          inet addr:192.168.108.13  Bcast:192.168.108.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe8f:68e7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:335609 errors:0 dropped:3107 overruns:0 frame:0
          TX packets:48332 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:131610506 (131.6 MB)  TX bytes:4424737 (4.4 MB)

eth1      Link encap:Ethernet  HWaddr 00:50:56:8f:0a:c6  
          inet addr:192.168.103.1  Bcast:192.168.103.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe8f:ac6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:18773 errors:0 dropped:0 overruns:0 frame:0
          TX packets:35645 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1816084 (1.8 MB)  TX bytes:50940327 (50.9 MB)

iptables -t nat -nvL

Chain PREROUTING (policy ACCEPT 3 packets, 375 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
   31  2604 DNAT       all  --  *      *       0.0.0.0/0            192.168.103.246      to:192.168.103.246

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
 1985  138K MASQUERADE  all  --  *      eth0    0.0.0.0/0            0.0.0.0/0           
    0     0 MASQUERADE  all  --  *      eth0    0.0.0.0/0            0.0.0.0/0           

Chain VL (0 references)
 pkts bytes target     prot opt in     out     source               destination 

iptables -nvL

Chain INPUT (policy ACCEPT 49159 packets, 38M bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 32 packets, 3393 bytes)
 pkts bytes target     prot opt in     out     source               destination         
13459  582K ACCEPT     all  --  eth1   *       0.0.0.0/0            0.0.0.0/0           
21264   38M ACCEPT     all  --  eth0   eth1    0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
    0     0 ACCEPT     all  --  eth1   eth0    0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
19109 1919K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0 


cat /proc/sys/net/ipv4/ip_forward 1
2
  • Post the output of this command on the linux machine: ifconfig ; iptables -t nat -nvL ; iptables -nvL; cat /proc/sys/net/ipv4/ip_forward
    – Fredi
    Oct 19, 2016 at 11:35
  • I have added...@Fredi Oct 19, 2016 at 11:59

3 Answers 3

2

You are using the same subnet on both networks, essentially it's like it being the same network. First change this, for example using 192.168.109.0/255.255.255 as subnet for your testing lab and retry.

Okay, now that you splited in two subnets, another thing i notice is that you have some firewalling rules and some NAT ones that to me at least do not make sense. Try flushing your iptables rules:

iptables -t nat -F
iptables -t nat -X
iptables -t nat -Z

iptables -F
iptables -X
iptables -Z

Then readd only the NAT one:

iptables -t nat -A POSTROUTING -o eth0 -J MASQUERADE

Then try pinging from a machine in the private lan a production one, thing should work.

9
  • Tried but having the same issue... Oct 19, 2016 at 12:27
  • Are you using the correct IP's on your private lan? I mean, are the machines there in the correct subnet? Can you correct the output of the comands and update your question? Another one, what's your requirement, to be able to connect from your private lan to production or the other way around?
    – Fredi
    Oct 19, 2016 at 12:29
  • Try configure : eth0 : 192.168.109.X/255.255.255 eth1 : 192.168.100.X/255.255.255
    – Str82DHeaD
    Oct 19, 2016 at 13:11
  • @Fredi ya i have checked the ip in private lan... The machine created under private lan will communicate each other. And added to this, IF i enabled the eth1 means, this private lan machines were able to ping linux machine.In that case, Prod to linux machine won't ping. Yup i need to communicate from private lan to Production using linux machine as router. Oct 19, 2016 at 13:30
  • @Str82DHeaD yes i have also tried that. eth0: 192.168.108.X eth1: 192.168.103.X .. having the same issue. Oct 19, 2016 at 13:32
2

As both interfaces are on same subnet , just bridge them by using below commands

brctl addbr bridge1

brctl addif bridge1 eth0

brctl addif bridge1 eth1

this should work

6
  • There's no point of the linux "router" in that case. Just a switch will do. He needs separate networks for prod and test.
    – Str82DHeaD
    Oct 19, 2016 at 13:11
  • need to create a single bridge and the connect 2 ethernet to that bridge ? or something else ? @8zero2.ops Oct 24, 2016 at 10:19
  • @DharaniDharan only one , as per your ifconfig output Oct 24, 2016 at 10:50
  • if i configured bridges between those interfaces .. i am not able to assign ip address to those nic .. am i right ? i need to configure default gateway of my production network as my ip address in that nic .. how i do this ?.And those configuration ddint work for me. Oct 24, 2016 at 14:23
  • You can give ip to bridge itself Oct 24, 2016 at 15:09
0

So as far as I understand you have following situation

subnet1 ---> eth0 -Linux PC- eth1 <----subnet 2

You are trying to use this Linux PC in the middle as a router between 2 subnets?

In this case do 2 things:
1) Disable iptables (just for test. You can enable them later and define your rules)
2) Enable ip forwarding on Linux PC. Add this to your /etc/sysctl.conf

ipv4.ip_forward = 1

and run

sysctl -p

Now in subnet 1 on hosts which need access to subnet 2 you will need to setup static routes.

Let's assume following subnets (based on your question)

subnet 1 192.168.108.0/24 eth0 .13

subnet 2 192.168.103.0/24 eth1 .1

In this case on hosts in subnet 1 you will need to run this

route add -net 192.168.103.0/24 gw 192.168.108.13

And on hosts in subnet 2 you will need to run this

route add -net 192.168.108.0/24 gw 192.168.103.1

After this ping initiated from hosts in subnet 1 to hosts in subnet 2 should work. And vice versa.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .