0

In Knockd how do I listen to a specific IP address from an interface that has multiple IP addresses?

Knockd only has the option to listen by interface but not an IP address.

Example

Interface eth0 has 3 IPs

  • 123.123.123.123
  • 124.124.124.124
  • 125.125.125.125

My target listen IP is 124.124.124.124 but if I start knockd with eth0 interface it will listen to the first ip 123.123.123.123.

2

1 Answer 1

1
+50

Knockd listens to the link layer, in the OSI model, this is layer 2. Layer 3 is where ip addresses live. Therefore, you will not be able to listen to only a single ip address.

The work around would be to create a MACVTAP, therefore creating a new layer2 device. Move the IP address of 124.124.124.124 to that interface, and running Knockd on the new interface eg macvtap0.

ip link add link eth0 macvtap0 type macvtap
ip address del 124.124.124.124/<insert the subnet> dev eth0
ip address add 124.124.124.124/<insert the subnet> dev macvtap0

Note: creating a macvtap, creates an interface with a new mac address, depending on your ISP/Upstream provider this may create an issue. If this occurs, add a route for outbound traffic from 124.124.124.124, to route through one of your other external IP address. So your upstream provider will see the mac address of the physical device. (this is the easiest way, I know there are other ways to have outbound traffic use the main mac address)

1
  • I found out the issue is knockd that comes in ubuntu 20 is v7.0 which only binds to the first IP of the interface and not all of it, the latest v8.0 binds to all of the interface IPs which solves my issue. Your method and idea is still valid for v7 and was similar to what I was trying to figure out ideas on how to implement it. Commented Dec 3, 2023 at 18:01

You must log in to answer this question.

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