How to get original destination port after REDIRECT of iptables?
Hi folks,
I have know that using REDIRECT option of iptables could redirect traffic to a specified remote port to another local port, for example iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 1888 -j REDIRECT --to-port 2000 . The original destination IP address is not changed, and could be obtained from getsockopt call with specifiying SO_ORIGINAL_DST ( e.g. getsockopt (client, SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&addr, &len_t );) .
What I want to do is that for every incoming packets to ether net interface, I want to direct to one spcific port, instead of dedirecting traffic from one port to another port. In another words, I want to do multi-port match one port instead of one to one port match. Could anybody suggest if it is doable? If yes, how could the application that listens to the re-directed port knows the original destination port?
Thanks a lot!
Grace Li
_________________________________________________________________
MSN Premium helps eliminate e-mail viruses. Get 2 months FREE* http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Quoted 6 lines · Grace Li
I have know that using REDIRECT option of iptables could redirect traffic to a specified remote port to another local port, for example iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 1888 -j REDIRECT --to-port 2000 . The original destination IP address is not changed, and could be obtained from getsockopt call with specifiying
SO_ORIGINAL_DST( e.g. getsockopt (client,SOL_IP,SO_ORIGINAL_DST, (struct sockaddr*)&addr,&len_t);) .
This also returns the port... the returned data is a sockaddr_in.
Regards
Henrik