Skip to content

A NSS module which maps a single host name to multiple IPs

License

Notifications You must be signed in to change notification settings

Cycatz/nss-host2ips

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NSS-Host2ips

Warning: This module is still testing, please use it carefully in the real environment.

Description

This is a NSS module which can map a single hostname to multiple IPs.

Motivation

I have a laptop and a NAS in my dormitory, and I need to switch my Wireguard VPN on my laptop frequently when I go out/get back, so I have to define three different host names mapping for public/private/wireguard ip for NAS, and use it depending on where I am or whether VPN is enabled. That is so tired!

Therefore, I come up with the idea that I can map a hostname to a fallback ip list, it can search through every fallback ip and check if the conditions are met, e.g, network interface.

Now I can happily use a single hostname to connect to my machine without worrying about which hostname I should use!

Installation

make 
sudo make install

Configuration

The configuration file default is /etc/host2ips

And you have to modify /etc/nsswitch.conf to insert the module.

e.g. /etc/nsswitch.conf

hosts:      host2ips files dns

Syntax

Sample of the config file:

# my host
host foo.bar
192.168.0.66   eth0      192.168.0.77
10.0.0.66      wg0       10.0.0.77
# my host2
host foo2.bar
192.168.1.22   eth1      192.168.1.23
10.0.1.22      wg1       -
123.123.123.1  -         -
  • Comment begins with #, currently does not support mixing comment and config
  • To define new host, begins with ‘host’ and the hostname
  • A host can have multiple fallback ips, the ip is used when all the conditions are satified
    • inteface name: specify the interface name
    • interface ip: specify the interface ip
  • - denotes don’t-care value

warning: don’t put any trailing spaces in each line

Todo

  • write test scripts
  • support host aliases
  • support IPv6
  • support more NSS lookup functions, e.g, gethostbyaddr()
  • support putting comments after line

Reference

About

A NSS module which maps a single host name to multiple IPs

Topics

Resources

License

Stars

Watchers

Forks