Results 1 to 3 of 3

Thread: iptables specific ip routing via tun

  1. #1
    Join Date
    Jul 2011
    Beans
    3

    iptables specific ip routing via tun

    hi guys!
    I was searching few days for a solution to my problem but haven't found one or I'm too dumb to understand.
    Here's what happened:
    I have a linux server used as a router. It has an eth0 and eth1 (local interface). I just installed openvpn (I need it only as a client), I configured it and run it. It connects very good the the vpn server but I don't know how to configure iptables so I can connect via tun only from an ip from the local network and all the others to connect normally to my external interface (eth0).
    I have tried the following command:

    iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o tun0 -j MASQUERADE
    which works very good except that all the traffic is forwarded thru tun0.
    when I put -s 192.168.1.12 (my local ip), also works fine but all the other computers from the network dont have internet access.
    let's say my server external ip is A.A.A.A, my local server ip is B.B.B.B and my tun ip is C.C.C.C
    how can I create a rule in order to make all ips (except one) to connect thru real ip A.A.A.A to the internet and my ip to connect thru tun ip C.C.C.C ?
    I don't seem to find an answer to that or as I said already I'm too dumb.
    Any help would be appreciated.
    Thanks guys.

  2. #2
    Join Date
    Jun 2011
    Location
    Atlanta Georgia
    Beans
    1,769
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: iptables specific ip routing via tun

    Quote Originally Posted by shamora View Post
    hi guys!
    I was searching few days for a solution to my problem but haven't found one or I'm too dumb to understand.
    Here's what happened:
    I have a linux server used as a router. It has an eth0 and eth1 (local interface). I just installed openvpn (I need it only as a client), I configured it and run it. It connects very good the the vpn server but I don't know how to configure iptables so I can connect via tun only from an ip from the local network and all the others to connect normally to my external interface (eth0).
    I have tried the following command:



    which works very good except that all the traffic is forwarded thru tun0.
    when I put -s 192.168.1.12 (my local ip), also works fine but all the other computers from the network dont have internet access.
    let's say my server external ip is A.A.A.A, my local server ip is B.B.B.B and my tun ip is C.C.C.C
    how can I create a rule in order to make all ips (except one) to connect thru real ip A.A.A.A to the internet and my ip to connect thru tun ip C.C.C.C ?
    I don't seem to find an answer to that or as I said already I'm too dumb.
    Any help would be appreciated.
    Thanks guys.
    The easiest method I can think of is defining specific rules for each range of ip's. This will take some planning in how you assign ip addresses, but it's the easiest way.

    for instance -s 192.168.1.12:20 would allow 12-20, then create a separate rule to send traffic from wherever else to where you want.

  3. #3
    Join Date
    Jul 2011
    Beans
    3

    Re: iptables specific ip routing via tun

    I have dhcp enabled on server and only on my computer there is a static ip which I wanna forward through vpn, all the others should connect directly to eth0 and ignore the tun ip. with the quoted command I managed to do that except that all the others just dont connect to the internet. and one more thing ... when I establish the vpn connection also cannot connect outside from the server console. tried mtr, ping, traceroute and so on. I guess I have to change some route & iptables rules but I dont have any idea which and how

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •