-   Linux - Networking (
-   -   DHCP overcomes my communication problems (

rickthemick 10-29-2004 08:35 AM

DHCP overcomes my communication problems
DHCP has a nice feature that I need in a program I'm coding (this post is related to some other posts I've made but has a new topic - DHCP)

I have problems with communicating between two hosts using completely different IP addresses (e.g [h1:, eth0] <---> [eth0 h2: eth1]) but are sitting on the same link and should do so.

The thing is that the hosts drops the packets from the other host, this can be solved by adding this:
route add default dev eth0
but this messes up the packet routing to for h2, since it's default gw (e.g will have conflicts with the new "default device". So this solution is not an option for me.

How DHCP solves this...(?)
Lets say h2 runs a DHCP server and h1 the DHCP client. This would cause no problems, h1 would send its discover to h2 and the process continous and h1 will finally get a new address say (I have tried it so it works). When I did this I saw on Ethereal that the source address was on the DHCP discovery packets arrive at the server!
-> Is this the trick (with src
-> Or how can the DHCP client get its packets to the DHCP server if it has a totaly different (current) IP address?
-> How is it possible to set the source address to in a UDP packet?

Best Regads

zatriz 10-30-2004 08:07 PM

why not assign virtual ip to each nic
the 10.0 would get a alias eth0:1 with 192. x
and the 192.x would get an alias eth0:1 with 10.x

but if all you want to do is get the src address to on a udp packet you could use a program like hping2 and script that to create a udp packet with whatever parameters you need.

r0b0 10-31-2004 03:28 AM

That's how dhcp discovery works. You ask a dhcp server for an IP address. You still don't have any address, so you use source address (and broadcast destination address).
If the client and the server sit on the same layer2 subnet, they see each others' packets and they are able to communicate.

rickthemick 11-01-2004 08:27 AM

Hurray, it works, thanks...

I've tried to change the source address using iptables:
iptables -t nat -A POSTROUTING -p udp -dport 5000 -j SNAT --to

this works fine but only for broadcast packets, why? I want it to change the unicast packets too... Ok, I'm tired right now but it seems a little odd to me!
(All other chains are empty)


All times are GMT -5. The time now is 12:13 PM.