selective masquerading


 
Thread Tools Search this Thread
Special Forums IP Networking selective masquerading
# 1  
Old 04-06-2009
selective masquerading

I am running Linux 2.6.20 on i686 architecture.

I want to be able to masquerade different hosts on my LAN to different external interfaces. Specifically, I want one specific host to masquerade through a vpn tunnel while the other hosts simply masquerade over the regular ISP interface. I only use one host to access the VPN, and its connection is unreliable (using microsoft ras) and I was hoping to be able to set up my linux server to handle maintaining the vpn connection (using its real ip as opposed to masquerading for the windows host).

eth0 = internal = 192.168.0.1
I tried setting up eth0:0 to be 192.168.1.1 and putting the said host in the 192.168.1.0/24 network, which works. So I'd be happy if I can masq 192.168.1.0/24 over the VPN and 192.168.0.0/24 over eth1's internet IP.

I tried this:
#iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE
#iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o ppp0 -j MASQUERADE

thinking I could maybe change the masquerade destination interface based on source IP, but traffic from 192.168.1.13 is still masquerading over the eth1 IP rather than ppp0. I'm stumped here. I really don't care to have the virtual interface; it just seemed like it would make things easier since the 192.168.0.0/24 network has several hosts that don't use the VPN all of which I want masqueraded via eth1.

As a last resort I suppose I could connect a second linux box to the VPN and have it masquerade the VPN and be the gateway for the VPN client(s), but that linux machine would itself be masqueraded by the main server, which opens it to having the same problems I am already having trying to get the masqueraded windows client to connect properly.

iptables is so amazingly powerful I'm sure what I want must be possible, but I am a bit of a novice. Any assistance will be greatly appreciated.

Thanks.
# 2  
Old 04-06-2009
UPDATE: I was able to get the selective masquerading to "work"... sort of.

The problem is if I don't have a default route for ppp0 then the 192.168.1.0/24 network can't reach anywhere. I add the default gw for ppp0 and then 192.168.0.0/24 can't reach anywhere.

What I don't understand at all though... if I have both default routes in, the linux server uses eth1 as its default, as evidenced by my source IP when I log in to internet sites. The vpn client machine (192.168.1.13) goes out over the VPN (ppp0) interface as expected. But my other lan clients (192.168.0.2 for example) can't get out to the internet if I try to masq over eth1 (but can f I switch it to masq over ppp0). What gives here? Both routes clearly work since the linux machine gets out over the ISP connection, so why can't it masquerade the ISP connection now, only the VPN?

My problem before was that I had the iptables service (under fedora) running, which seemed to not allow me to delete the original MASQUERADE directive to forward all traffic (regardless of source) via eth1. Now with my tables loaded manually the based-on-source part seems to work, just only with one internet connection (ISP or VPN) as its destination at a time. My hair's falling out here. This makes even less sense than the last situation did.

The masquerade will only work over whichever is the last default route added, even though linux seems to be smart enough to route through eth1 by default for its own local traffic despite the existence of the second "default" route.

Last edited by NESter; 04-06-2009 at 06:19 AM.. Reason: update
# 3  
Old 04-06-2009
Well, I guess I jumped the gun in asking for help. I spent more time searching and came upon the solution. In case anyone wants it, here it is:

I added the virtual network eth0:0 as stated above. I put the clients I want to be masqueraded over the vpn onto that subnet. then I bring up the ppp0 interface for the VPN. I don't have it set up a default route at all. then I set up a separate table for the LAN to be sent to the subnet:

ip route flush table 18
ip route add table 18 to 192.168.1.0/24 dev eth0:0
ip route add table 18 to default via $PPP_REMOTE dev ppp0
ip rule add from 192.168.1.0/24 table 18 priority 18

18 is just an arbitrary number.

I discovered the solution here:
Linux Route Hacks

I just adapted the data presented there to my situation. wow. a few hours well spent.
# 4  
Old 04-06-2009
Thanks for sharingSmilie
# 5  
Old 04-06-2009
new twist

Well, since I got it working a couple of new wrinkles have appeared.

First, I am getting the Protocol-Reject for unsupported protocol messages after a bit, requiring me to kill pppd and bring the vpn back online to resume. I've seen plenty of posts out there about this, so I'll keep reading and hopefully find something there.

UPDATE: wow. I'm silly. i solved the REALLY confusing wrinkle. now I just have to figure out this protocol-reject death loop thing.

Last edited by NESter; 04-06-2009 at 03:25 PM.. Reason: update
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Sendmail - Masquerading multiple domains with different addresses

Hello Friends, I am running Sendmail 8.14 on rhel6. I have one simple question regarding domain masquerading, i would want to masquerade different domains with different addresses. By that what i mean is that lets say i have 3 domains as home.com, example.com, test.com and i would want to... (0 Replies)
Discussion started by: Rohit Bhanot
0 Replies

2. UNIX for Dummies Questions & Answers

Help with selective ls

Hi all :wall: Can anyone advise how do I use ls to do a selective amd sorted listing of file that I want to have as below? Am looking for files that are named as log_<nnnn>.txt, where <nnnn> are numeric, i.e. I want to have a listing sorted from the newest to the oldest of files that... (7 Replies)
Discussion started by: newbie_01
7 Replies

3. AIX

sendmail masquerading on AIX.

Hello all, I have a requirement wherein I need to change the "received from" address parameter for outgoing mails from an AIX server. I tried using the option to specify the "reply-to" address, still my relay server rejects the mails as the "received from" address still contains . I know,... (1 Reply)
Discussion started by: thisissouvik
1 Replies

4. UNIX for Dummies Questions & Answers

Sending mail as another user (username masquerading)

I have sendmail as the smtp server. I want that all mails sent from user1 actually appears to come from user2(also should be reflected in mail header). How can i accomplish the task by tweaking sendmail or are there any other means to do so? (4 Replies)
Discussion started by: proactiveaditya
4 Replies

5. AIX

Mutt/Sendmail Masquerading Problem on AIX 5.3

We are running Unix AIX 5.3 and I have been asked to masquerade the sender name on our email processing. We have one domain name and many users: user1@domainname user2@domainname user3@domainname We use mutt/sendmail to do our email processing. I discovered that using genericstable within... (1 Reply)
Discussion started by: FHMARTINS
1 Replies

6. IP Networking

howto start with gateway / router / masquerading

Hi there, I have only basic knowledge in Unix but I'm eager to learn. I have a new complex (for me) exercice and I have no idea how to start. I have a regular network on witch I'm trying to plug another network. Here is an image of the physical network.... (7 Replies)
Discussion started by: chebarbudo
7 Replies

7. SCO

Sendmail masquerading

I am having a problem with my sendmail configuration I have masquerading on but when I send a mail to multiple people it masquerades my email but not the others? see the sample below: From: name@vegena.net Sent: Friday, July 24, 2009 9:42 AM To: name2@atksco1.vegena.net;... (0 Replies)
Discussion started by: garycrow
0 Replies

8. Linux

postfix configuration issues...specifically masquerading (lack of )

postfix configuration issues...specifically masquerading (lack of ) Mail sent to our intranet arrives correctly (me@domain.com). Mail sent to our intranet arrives correctly (me@domain.com). Anything going outside does not, so my tests get rejected (me@hostname.com) :( any assistance... (5 Replies)
Discussion started by: mr_manny
5 Replies

9. UNIX for Dummies Questions & Answers

Sendmail Masquerading

Hi, I'm trying to get my mails sent from the address user@domain instead of user@hostname.domain. Should be simple masquerading configuration in sendmail config files, but this is where I fall (newbie). The sendmail.cf is not recommended for editing. There should be some kind of .mc file that... (0 Replies)
Discussion started by: shimpanzo
0 Replies

10. IP Networking

IP Masquerading

Hello I am trying to setup a nework using IP Masquerading. I followed the instructions/ steps as follows: 1. Appropriated a multi-homed box 2. I have installed Redhat Linux 8.0 on it (base install) 3. INetwork settings eth0 192.168.0.1 netmask 255.255.255.0 eth1 a static IP my... (4 Replies)
Discussion started by: skotapal
4 Replies
Login or Register to Ask a Question