Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sloev
Last active October 26, 2015 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sloev/5435400e42cc0eea3bb6 to your computer and use it in GitHub Desktop.
Save sloev/5435400e42cc0eea3bb6 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Network configuration for basic server
# ­ using '/bin/ip'
#
# Note: hostname and the lo interface are
# set up by boot.localnet
#
ip="/bin/ip"
dev=eth0
myIP="192.168.149.XX/25"
# For XX refer to the note "Server IP Addresses"
router="192.168.149.1"
#
case "$1" in
start)
echo "Starting the network"
#
# 1. The ethernet interface
#
$ip link set up dev $dev
$ip addr add $myIP dev $dev brd +
#
# 2. The default gateway
#
$ip route add default dev $dev via $router scope global
;;
stop)
echo "Stopping the network"
$ip route del default
$ip addr del $myIP dev $dev
$ip link set down dev $dev
;;
restart)
# stop the network and start it again
$0 stop
$0 start
;;
*)
echo "Usage $0 [start|stop|restart]"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment