iptables, allow access from certain MAC addresses

26,825

Solution 1

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.

Solution 2

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.

Share:
26,825

Related videos on Youtube

user788171
Author by

user788171

Updated on September 18, 2022

Comments

  • user788171
    user788171 over 1 year

    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.

  • user9517
    user9517 almost 11 years
    A MAC address over the internet ?
  • user788171
    user788171 almost 11 years
    There's no way to do this then for devices on different networks, e.g. MAC address over the internet?
  • Izzy
    Izzy almost 11 years
    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..