0

I'm using iptables on my router to redirect all web traffic to my page.

But i don't know how to except my mac address list.

I did command like this:

iptables -t nat -A PREROUTING -m mac ! --mac-source xx-xx-xx-xx-xx-xx -p tcp --dport 80  -j DNAT --to 127.0.0.1:8080 (Host A)
iptables -t nat -A PREROUTING -m mac ! --mac-source xx-xx-xx-xx-xx-xx -p tcp --dport 80  -j DNAT --to 127.0.0.1:8080 (Host B)

But it just execute command for host A. It means Host A can access web normally but Host B still got redirect.

How can i got access normally for both mac address?

0

Use this:

iptables -t nat -A PREROUTING -m mac --mac-source xx-xx-xx-xx-xx-xx -j ACCEPT (Host A)
iptables -t nat -A PREROUTING -m mac --mac-source xx-xx-xx-xx-xx-xx -j ACCEPT (Host B)
iptables -t nat -A PREROUTING -p tcp --dport 80  -j DNAT --to 127.0.0.1:8080

The first two commands ACCEPT packets from A and B, so redirection only happen if the packet is from another host.

  • With your order all work perfectly. But what if i want add more mac address after the third commands? Thank you so much for your answer! – Trần Minh Phương Feb 18 '15 at 10:06
  • @TrầnMinhPhương You can insert a command in the middle with "iptables -I". – user4098326 Feb 18 '15 at 10:09
  • Sorry i don't understand. What is your mean? – Trần Minh Phương Feb 18 '15 at 10:12
  • @TrầnMinhPhương I assume you were asking how to add more addresses after executing my commands. Or were you asking what would the commands be if you want more addresses? – user4098326 Feb 18 '15 at 10:15
  • Yes, after execute your third command, all traffic will redirect. I want add more mac address like this: <pre>iptables -t nat -A PREROUTING -m mac --mac-source xx-xx-xx-xx-xx-xx -j ACCEPT</pre> after execute your third command. – Trần Minh Phương Feb 18 '15 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.