Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- [ -z "$1" -o -z "$2" ] && echo "iface action" && exit 0
- if [[ "$2" == "up" ]]; then
- sed -i -r "s/iface $1.*$/iface $1 inet static/" /etc/network/interfaces
- sed -i "/iface $1/!b;:x;n;s/^#\+//;/^$/b;bx" /etc/network/interfaces
- echo -n "Enter new address: "
- read new_address
- echo -n "Enter new netmask: "
- read new_netmask
- echo -n "Enter new gateway: "
- read new_gateway
- echo -n "Enter new DNS1: "
- read dns1
- echo -n "Enter new DNS2: "
- read dns2
- if [[ $new_address ]]; then
- sed -i -r "/iface $1/!b;:x;n;s/address.*/address $new_address/;t;/iface/b;bx" /etc/network/interfaces
- fi
- if [[ $new_netmask ]]; then
- sed -i -r "/iface $1/!b;:x;n;s/netmask.*/netmask $new_netmask/;t;/iface/b;bx" /etc/network/interfaces
- fi
- if [[ $new_gateway ]]; then
- sed -i -r "/iface $1/!b;:x;n;s/gateway.*/gateway $new_gateway/;t;/iface/b;bx" /etc/network/interfaces
- fi
- #sed -i "/$2 $3/s/^#\+//" ~/interfaces
- #temporary parm
- if [[ -z `cat /etc/network/interfaces | grep $1` && $new_address && $new_netmask && $new_gateway ]]; then
- ifdown $1
- ip addr add $new_address/$new_netmask dev $1 label $1
- ip route add default via $new_gateway dev $1 onlink
- else
- ifdown $1
- ifup $1
- fi
- #temporary dns
- if [ "$dns1" ]; then
- echo -e "nameserver $dns1" > /etc/resolv.conf
- if [ "$dns2" ]; then
- echo -e "nameserver $dns2" >> /etc/resolv.conf
- fi
- #else echo "" > /etc/resolv.conf
- fi
- fi
- if [[ "$2" == "down" ]]; then
- if [[ -z `cat /etc/network/interfaces | grep $1` ]]; then
- ip route del default dev $1 2>&1 1>/dev/null || true
- ip -4 addr flush dev $1
- ip link set dev $1 down
- echo "" > /etc/resolve.conf
- else
- ifdown $1
- #echo "" > /etc/resolve.conf
- fi
- fi
- exit 0
Add Comment
Please, Sign In to add comment