Skip to content

serfreeman1337/ip-updater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ip-updater

Modify files and maybe do some other stuff based on IP address changes on Linux.
This was built to update DNS IPv6 addresses in /etc/hosts for systemd-resolved to use.
Yes, I'm using systemd-resolved on my home router as local DNS server.

Configuration

Example config.toml:

[[config]]
interfaces = [ "lan0", "lan1" ] # Only trigger for specified interface updates.
# ipv4_only = true              # Only trigger for ipv4 address updates.
ipv6_only = true                # Only trigger for ipv6 address updates.
action_delay = 500              # Wait time in milliseconds before executing any actions.

# Update DNS addresses in /etc/hosts.
[[config.actions]]
type = "update_file"
file = "/etc/hosts"             # File path.
tag_start = "# ip-updater"      # Start and end tags within a file.
tag_end = "# ip-updater"        # Everything within the tags will be replaced according to the template. 
# Template format:
# "<(match interface)|(match ipv4 or ipv6 address)|(match address network)|(apply address suffix)>"
# The template will generate a line for each matching address.
# Examples:
#   <lan0>                     - Add every address on the "lan0" interface.
#   <lan0|ipv6>                - Add every IPv6 address on the "lan0" interface.
#   <lan0|ipv6|::10>           - Add every IPv6 address on the "lan0" interface and apply address suffix.
#   <lan0|ipv6|2a05::/16>      - Add every IPv6 address in the 2a05::/16 network on the "lan0" interface.
#   <lan0|ipv6|2a05::/16|::10> - Add every IPv6 address in the 2a05::/16 network on the "lan0" interface and apply address suffix.
template = [
  "<lan0|ipv6>		router router.local",
  "<lan1|ipv6>		router router.local",
  "<lan0|ipv6|::11>		srv-1 srv-1.local",
  "<lan0|ipv6|::12>		srv-2 srv-2.local",
  "<lan1|ipv6|::11>		srv-1 srv-1.local",
  "<lan1|ipv6|::12>		srv-2 srv-2.local"
]

# Update IPv6 DNS addresses to advertise with systemd-networkd.  
[[config.actions]]
type = "update_file"
file = "/etc/systemd/network/10-lan0.network"
tag_start = "# ip-updater"
tag_end = "# ip-updater"
template = "DNS=<lan0|ipv6>"

[[config.actions]]
type = "update_file"
file = "/etc/systemd/network/20-lan1.network"
tag_start = "# ip-updater"
tag_end = "# ip-updater"
template = "DNS=<lan1|ipv6>"

[[config.actions]]
type = "exec"
exec = "networkctl reload" # Command to execute. Templates are allowed.

Build

cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build

About

Modify files and maybe do some other stuff based on IP address changes on Linux

Topics

Resources

License

Stars

Watchers

Forks

Contributors