A simple script for turning up the eth interface and get ip address via dhcp.
#!/bin/bash
#Author: Cyrus
#Purpose: A simple bash script that turns on eth interface and acquire IP address from dhcp server.
n=$1
if [ $n -ge 0 ]
then
ifconfig eth$n up; dhclient eth$n
#ifconfig eth$1 up; dhclient eth$1
else
echo “There is no eth id that is less than 0”
fi
#End
This script is for my ArchLinux vm, I am building it from core installation, and I think I will learn a lot of things from this experience.
ifconfig $(ifconfig -a | grep -i eth | cut -f 1 -d ‘ ‘) up; dhclient $(ifconfig -a | grep -i eth | cut -f 1 -d ‘ ‘)
This command line works only for one ethernet interface…Not sure how can I store the long command string (ifconfig -a |grep -i eth | cut -f 1 -d ‘ ‘) into a variable and use it….
One thought on “Bash script: Turn up eth”