2

I have a linux machine with 2 network connections, wlan0 and eth0. Through wlan0, the linux machine is connected to the router, and through eth0, the linux machine is connected to the IP camera (via a network switch).

From a windows machine on the same network as wlan0, I connect to the linux machine using putty. How can I connect to the ipcamera on eth0, through my windows machine connected via wlan0?

IP of my linux machine, connected via wlan0 is 192.168.100.10 (gateway: 192.168.100.1)

IP of IP camera, connected to linux machine via eth0, using a switch, is 192.168.1.10 (gateway 192.168.1.1)

When I am on my linux machine, I can connect to both wlan0, and to eth0, and access the IP camera, but when I try to connect to eth0 through my windows pc, which is connected to the same router as wlan0, I can not connect to eth0.

How can I forward the IP Camera eth0 connection to my wlan0 connection so I could access it from my Windows PC?

I have IP forwarding enabled.

Here is my interfaces configuration:

# Local loopback
auto lo
iface lo inet loopback

#Wireless
#Uplink1 Wireless
auto wlan0
iface wlan0 inet static
    wpa-ssid wifi
    w8a-psk 90509d8a2bcd0893a2b873e5d9ba9c96ec686ce2b90e3252eab680fdef1c6125
    address 192.168.100.10
    netmask 255.255.255.0
    gateway 192.168.100.1
    post-up ip route add 192.168.100.0/24 dev wlan0 table uplink1
    post-up ip route add default via 192.168.100.1 table uplink1
    post-up ip rule add from 192.168.100.10/32 table uplink1 priority 100
    post-up ip route flush cache
    pre-down ip rule del from 192.168.100.10/32 table uplink1 priority 100
    pre-down ip route flush table uplink1
    pre-down ip route flush cache

    #Uplink2
    auto eth0
    iface eth0 inet static
    address 192.168.1.118
    netmask 255.255.255.0
    #gateway 192.168.1.1
    post-up ip route add 192.168.1.0/24 dev eth0 table uplink2
    post-up ip route add default via 192.168.1.1 table uplink2
    post-up ip rule add from 192.168.1.118/32 table uplink2 priority 110
    post-up ip route flush cache
    pre-down ip rule del from 192.168.1.118/32 table uplink2 priority 110
    pre-down ip route flush table uplink2
    pre-down ip route flush cache

The output of ifconfig is:

eth0      Link encap:Ethernet  HWaddr 02:41:06:40:b3:e9
inet addr:192.168.1.118  Bcast:192.168.1.255  Mask:255.255.255.0
inet6 addr: fe80::41:6ff:fe40:b3e9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:1064 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:63840 (62.3 KiB)  TX bytes:558 (558.0 B)
Interrupt:46

lo        Link encap:Local Loopback
inet addr:127.0.0.1  Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING  MTU:65536  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 00:a1:b0:f0:63:e4
inet addr:192.168.100.10  Bcast:192.168.100.255  Mask:255.255.255.0
inet6 addr: fe80::2a1:b0ff:fef0:63e4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:1369 errors:0 dropped:0 overruns:0 frame:0
TX packets:790 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:126212 (123.2 KiB)  TX bytes:102124 (99.7 KiB)

Output of route is:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.100.1   0.0.0.0         UG    0      0        0 wlan0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
192.168.100.0   *               255.255.255.0   U     0      0        0 wlan0

I already tried to do the IP forwarding via iptables but without any results. I tried: iptables -t nat -A PREROUTING -p tcp -d 192.168.1.10 --dport 80 -j DNAT --to 192.168.100.10:80

and iptables -A FORWARD -p tcp -d 192.168.100.10 --dport 80 -j ACCEPT

I also tried iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.100.10:80

But I can still not access 192.168.1.10 on my windows PC. I write in the url 192.168.100.10 since I am connected via wlan0 to it, and I try to forward the IP camera connection to that url.

2 Answers 2

0

When your windows computer queries 192.168.1.10, its routing table is akin to:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.100.1   0.0.0.0         UG    0      0        0 wlan0
192.168.100.0   *               255.255.255.0   U     0      0        0 wlan0

So, all traffic will go through your router. Your router doesn't have any awareness of the linux box's eth0 port or the network you've created on that machine. You would have to instruct the router to route the 192.168.1.* block to your Linux machine. Which, depending on your router, may or may not be possible.

-1

After trying many methods, I finally got this to work.

Here is what I did that forwards the Ip of IP Camera on eth0 to my wlan0 connection, which I can access from my Windows or from any PC from the internet.

So I added:

iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 8080 -j DNAT --to 192.168.1.10:80

iptables -t nat -A POSTROUTING -p tcp -d 192.168.1.10 --dport 80 -j MASQUERADE

And now everything works fine. The ip of my camera (192.168.1.10:80 on eth0) if being forwarded to the ip of my other connection on the linux box (192.168.100.10:8080), on wlan0.

So now when I am in my windows pc, connected to the same router as the wlan0 conenction, when I write 192.168.100.10:8080, it shows the login page of my IP camera on 192.168.1.10.

You must log in to answer this question.

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