iptables specific ip routing via tun


 
Thread Tools Search this Thread
Special Forums IP Networking iptables specific ip routing via tun
# 1  
Old 07-14-2011
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:

Code:
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o tun0 -j MASQUERADE 
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.

Last edited by pludi; 07-15-2011 at 03:57 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Unable to connect guest VM to internet (QEMU via both 'User-mode networking' and 'TUN/TAP')

Hello, I installed FreeBSD 10.3 on AQEMU. I can't connect to internet in none of the modes of "Default, User-Mode Networking" and "TUN/TAP Networking". I am able to ping my host in the TAP networking mode (192.168.1.33 which is my IP addr in guest), but getting 'no route to host' for any... (1 Reply)
Discussion started by: temp-usr
1 Replies

2. UNIX for Dummies Questions & Answers

iptables / ip route packet routing with multiple gateways

Hi all. Linux noob here. I was hoping someone could help me with configuring some routing rules on my router, an Asus AC68. The router is connected to two gateways, wan0_gateway and wan1_gateway. I have rules set up in the router gui that will push all traffic from every IP other than my own... (0 Replies)
Discussion started by: Bishi
0 Replies

3. IP Networking

iptables - MAC routing

Hi all, I have a solution where a system can have multiple physical interfaces but a single IP address. I am looking to insert a Squid proxy (that will also perform source NAT), but the return packets must go back to the correct interface. client network is 10.x.x.x network between the... (4 Replies)
Discussion started by: wabbit02
4 Replies

4. Linux

[SOLVED] Trouble adding Tun module

So I have Ubuntu running on a sheevaplug develop kit, but the damn kernel thing doesn't come with /dev/tun enabled. It was suggested that I look into using module assistant to compile & get this set up but I'm having issues. Linux ubuntu 2.6.39.4 #2 PREEMPT Fri Aug 5 19:05:11 MDT 2011 armv5tel... (4 Replies)
Discussion started by: dpreviti
4 Replies

5. Solaris

Solaris 10 crashes upon boot after TUN driver installed

Hey! I compiled TUN 1.1 driver on my Solaris 10 64bit, and everything was working fine, all the commands for installation were successfull (add_drv, devfsadm -i tun ... etc.) and the driver was working fine as I got OpenVPN server up and running with successful clients attached. My only problem... (2 Replies)
Discussion started by: TomSu
2 Replies

6. UNIX for Dummies Questions & Answers

Routing or Iptables connections by hostname or ip address

edit; I found a solution that works, see thread #3 https://www.unix.com/302417065-post3.html Hi there, I have a small dedicated server that has four ip addresses and by default my httpd sends request using the servers main ip for all outbound connections. I'm quite amateur at routing and... (4 Replies)
Discussion started by: mooofa
4 Replies

7. IP Networking

Specific routing problem help needed

Hi, I am trying to set up the following : - One linux box connected to the net, static address, eth0 - No other eth interface on the box I want to set up this box in a way it can accept remote connections, like pptp tunnels (which seems the easier to set up unless you have other idea)... (2 Replies)
Discussion started by: aerostar700
2 Replies

8. IP Networking

IP Routing

I am using RedHat Linux 9, In this box their are two lan intefaces. eth0 ====> LAN 192.168.100.100 255.255.255.0 eth1 ====> Internet Static IP 255.255.255.0 59.144.168.226 (Gateway) I want to define a gateway 59.144.168.226 for my LAN... (2 Replies)
Discussion started by: jaibw
2 Replies

9. UNIX for Dummies Questions & Answers

routing

Can anyone help with the following; I am working on a unix server (Apple OS X Server). We have two network cards in the server. Both cards are on different subnets i.e en1 is on 192.168.10.10/24 and the built in ethernet is on 10.10.150.10/24. From a computer plugged into en1 (and set to ip... (5 Replies)
Discussion started by: mrthrt
5 Replies

10. IP Networking

Routing

I have SCO Unix. I have 2 routers. as it is now, when someone telnets to UNIX and goes through router #1 everything is fine. The users who go through router #2 can not connect at all. I talked to CISCO and they said I need to set up a second Gateway on UNIX. They said what is happening is that... (1 Reply)
Discussion started by: john fli
1 Replies
Login or Register to Ask a Question