Presently, I limit which clients can access my server by using IP addresses via iptables, only approved IP addresses can connect.

However, the problem with this is if a client is on a laptop and goes to a different location, they can no longer connect because the IP has changed.

For a variety of reasons, iptables authentication is the only option I have.

Is there a way to restrict access by device instead of ip address. For instance, only allow certain MAC address to connect to port 5000.

Is it possible to do this via iptables? Note, the computers are not on the same network, they could be connecting from anywhere in the world.

3 Answers 3


You can't do this because MAC addresses aren't available to you for connections that have traversed the internet.

To do what you want it would be much safer to setup a VPN and only allow connections via that to your critical infrastructure. If you can't do that then you could try setting up some sort of two factor authentication.

If you really are stuck with just iptables then you may get by with port knocking. There appears to be a fairly good tutorial on this in the Arch Linux wiki but heed the warning and don't use the example ports/sequence in your environment.

A combination of the above would techniques be even better.


Iptables has a mac module. You can use it like this:

/sbin/iptables -A INPUT -m mac --mac-source 00:0F:EA:91:04:08 -j DROP

nixCraft has an extensive guide on how to create filter rules based on mac addresses.

But this only works on the same network, as MAC addressing is link-layer specific and won't get forwarded when using routing. So, as long as the devices are on different networks that need routing, this won't work.

  • A MAC address over the internet ?
    – user9517
    Commented Jun 28, 2013 at 23:10
  • There's no way to do this then for devices on different networks, e.g. MAC address over the internet?
    – user788171
    Commented Jun 28, 2013 at 23:22
  • My fault, unintentionally skipped the last paragraph. Added explanation for that. It may be possible to get it working with a VPN, not sure about that, though..
    – Izzy
    Commented Jun 28, 2013 at 23:22

For the list of MAC addresses, assuming these are stored in a file line by line (mac_addresses_file), you can use:


for MAC in `cat mac_addresses_file`; do

  **iptables -A FORWARD -i eth0 -o eth1 -m mac --mac-source $MAC -j ACCEPT**


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .