Iptables to change source IP


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Iptables to change source IP
# 1  
Old 12-08-2010
Iptables to change source IP

Hey everyone!
I am trying to configure iptables/netfilter so that all traffic coming from a certain port (8001) has its source ip re-written as a different ip. Can this be done?

Basically its a possible workaround for another issue I'm having with a multihomed server. SNMP data is coming in on one IP, and they're being responded to using the incorrect IP. So, I need all packets sent from the snmp agent to have the source ip re-written as the correct source ip. Any ideas?
# 2  
Old 12-08-2010
Do you mean changing the source ip of a packet arrives at a the snmp server before the packet is dispatched to snmp daemon by kernal(of the snmp server)?

It is hard to do so, cuz SNAT is only usable from POSTROUTING.

SNAT at POSTROUTING

Last edited by vistastar; 12-09-2010 at 02:30 AM..
# 3  
Old 12-09-2010
The snmp request comes in and is received by the SNMP daemon running on the system. It generates a reply, however when it generates the reply it uses the IP of another interface on the system. Because of routing rules in place, that IP gets forwarded out of a different interface. So what I need to do is change the source IP in the SNMP reply before it hits the routing tables configured in IPROUTE2, so it can then have the correct route applied and be sent out the correct interface.

The IP address it's trying to reply with is a real address, but its on a different network than the management network. So when the reply gets sent out, its not routable to the requestor. It also is stopping traps from working.

Last edited by msarro; 12-09-2010 at 11:16 AM..
# 4  
Old 12-11-2010
Try this command:

Code:
$sudo iptables -t nat -I POSTROUTING -s IP1 -p udp --sport SNMP_PORT -j SNAT --to IP2

IP1 is the wrong ip your snmpd is using to reply requests.
IP2 is the right ip you want.
SNMP_PORT is the port number of snmpd.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. SCO

How to change raid controller driver ? (hardware change)

Hello I'm trying to virtualize an instance of Sco Unix 5.0.5 in VirtualBox (called VM-A) , but sco I have problems set to launch with the new raid controller . The physical machine has a raid controller adaptec (alad driver) but VirtualBox uses buslogic (blc driver) What ... (3 Replies)
Discussion started by: flako
3 Replies

2. IP Networking

Change source ip on static internet

Hi, Environment: Linux: Ubuntu 12.04 I am connected to internet using static ip. This means my internet provider Pacenet has assigned me static ip. Now, whenever I am trying to change source ip for tcp/ip (ip4) using iptables firewall, I am unable to access internet at all. Can anybody... (4 Replies)
Discussion started by: ashv
4 Replies

3. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (7 Replies)
Discussion started by: ust3
7 Replies

4. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (0 Replies)
Discussion started by: ust3
0 Replies

5. Shell Programming and Scripting

How to change values in datafile from source file

Hi all, I have this source file source.txt : hdrEthernetSwitch1IPAddress 112.13.9.34 hdrEthernetSwitch2IPAddress 112.13.8.245 noOfRevASLAvailable 8000 noOfRevASLInUse 122 maxDOSPayload 7777 pcmdEvdoRUM Enabled pcmdEvdoFlow Enabled And I have this datafile to be modified : ... (5 Replies)
Discussion started by: luna_soleil
5 Replies

6. Shell Programming and Scripting

Source

I have a script in /etc/rc2.d that needs to run on boot up the file looks like this #!/sbin/sh source /abc/scripts/test_env.sh /abc/xyz/run I need to source the test_env.sh script they are both bash how do i do that? 'source /abc/scripts/test_env.sh' I am not too sure (3 Replies)
Discussion started by: deaconf19
3 Replies

7. Shell Programming and Scripting

. and source

What's the difference of using "." and "source", such as ". .bashrc" and "source .bashrc"? (1 Reply)
Discussion started by: learn
1 Replies

8. UNIX Desktop Questions & Answers

Change time source?

I need to change the time on my SUN box, it is five minutes fast. (4 Replies)
Discussion started by: michelemcdonald
4 Replies

9. UNIX for Dummies Questions & Answers

qt from source

i'm installing qt from source, and while making i get an error having to do with a "pthread library." what libraries do i need to install for qt to compile, and where can i get them? (1 Reply)
Discussion started by: nydel
1 Replies
Login or Register to Ask a Question