Network-Interfaces-Script (Ver 1.1)

Read and update awk scripts for Ubuntu /etc/network/interfaces file.

readInterfaces.awk -- parse and output interface configuration changeInterface.awk -- modify interfaces file

Parse Interfaces Script

Complete re-implement both scripts with much simpler logic, shorter code and pack with more flexible features. It now allows you to add/modify/delete interfaces, as well as add/modify/delete any settings within an interface. These scripts are tested with python script.

Update Interfaces Script (changeInterface.awk)

Here is the standard usage for changeInterface.awk:

awk -f changeInterface.awk <interfaces file> <device=ethX> <mode=(dhcp|static|manual)> [action=add|remove] [address=<ip addr> netmask=<ip addr> <name=value> ...]

Usage Examples:

Configure network device eth0 to DHCP mode awk -f changeInterfaces.awk /etc/network/interfaces device=eth0 mode=dhcp Add a network device p3p1 with static settings awk -f changeInterfaces.awk /etc/network/interfaces device=p3p1 action=add mode=static address= netmask= gateway= If p3p1 already exists and configured as DHCP, it will automatically modify to static interface with all the input settings.

If p3p1 already exists and configured as static, it will overwrite the existing field or add the field if it is new.

Delete an interface entry awk -f changeInterfaces.awk /etc/network/interfaces device=eth1 action=remove

Remove network & broadcast fields and add (or modify if exists) dns-nameservers & foo fields awk -f changeInterfaces.awk /etc/network/interfaces device=eth1 mode=static network= broadcast= foo=bar 'dns-nameservers='

Read Interfaces Script (readInterfaces.awk)

Here is the standard usage for readInterface.awk:

awk -f readInterfaces.awk <interfaces file> <device=ethX> [output=all] * output=all - print out the full settings for an interface. Without this option, the script will just print out the basic address config in : ipaddr netmask gateway (separated with a single white space). With this option, all the settings are displayed, e.g. bridge_maxage 12 broadcast network bridge_stp off bridge_fd 9 bridge_ports eth0 bridge_hello 2