0

I am working on one Linux box. I want something like this.

network--->wlan0---->eth0-->other server.

Both wlan0 and eth0 interface reside inside same Linux box. I am using dhcp which is assigning something say 192.168.3.21 to my wlan0 interface. I am assigning static IP say 192.168.3.101 to my eth0 interface and 192.168.3.102 to other server. Now, I want to ping from the network(192.168.3.XX) to other server at the address of 192.168.3.102 and my eth0 at 192.168.3.101. I am unable to do so.

I am not even able to ping my other server at 192.168.3.102 from my linux box.

I have enabled ip forwarding via "echo 1 > /proc/sys/net/ipv4/ip_forward" command.

I have used the following command to enable nat forwarding too.

iptables -A FORWARD -i wlan0 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth0 -o wlan0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Still I am unable to ping.

Please, let me know what I am missing. Any help will be so much appreciated.

Here is the output of iptables-save :-

# Generated by iptables-save v1.6.0 on Mon Feb 19 10:17:54 2018
*raw
:PREROUTING ACCEPT [481:39595]
:OUTPUT ACCEPT [325:24634]
COMMIT
# Completed on Mon Feb 19 10:17:54 2018
# Generated by iptables-save v1.6.0 on Mon Feb 19 10:17:54 2018
*nat
:PREROUTING ACCEPT [1:229]
:INPUT ACCEPT [1:229]
:OUTPUT ACCEPT [1:76]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o wlan0 -j MASQUERADE
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Mon Feb 19 10:17:54 2018
# Generated by iptables-save v1.6.0 on Mon Feb 19 10:17:54 2018
*mangle
:PREROUTING ACCEPT [482:39927]
:INPUT ACCEPT [474:38801]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [325:24634]
:POSTROUTING ACCEPT [325:24634]
COMMIT
# Completed on Mon Feb 19 10:17:54 2018
# Generated by iptables-save v1.6.0 on Mon Feb 19 10:17:54 2018
*filter
:INPUT ACCEPT [63:6229]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1:76]
-A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
COMMIT
# Completed on Mon Feb 19 10:17:54 2018

Here is my output for ip route:-

default via 192.168.0.1 dev wlan0 metric 10 192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.190 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.235

  • Please show output for iptables-save. – Alexander Tolkachev Feb 19 '18 at 10:01
  • Maybe your netmasks clash. Please edit to add output of ip route – kubanczyk Feb 19 '18 at 12:35
0

If you want to have a router with two interfaces, they need to be on separate subnets (example 192.168.0.0/24 is separate from 192.168.5.0/24). You have a clash here, visible in your ip route, it won't work.

If you want to use the same subnet on both interfaces, it's not a router, it's a two-port switch, which is commonly called a bridge.

  • You could create one bridging interface and assign one IP there, possibly via DHCP.
  • The wlan0 and eth0 should be left without IP addresses, they become transparent members of a bridge.
0

To connect two different networks, one need to use bridge like below:

Create the bridge interface

brctl addbr br0

Add interfaces to the bridge

brctl addif eth0

brctl addif wan0

Zero IP the interfaces.

ifconfig eth0 0.0.0.0 promisc up

ifconfig wan0 0.0.0.0 promisc up

Enable the bridge interface

ifconfig br0 10.0.1.1 netmask 255.255.255.0 broadcast 10.0.1.255 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.