Created
September 14, 2012 08:42
-
-
Save hcooper/3720821 to your computer and use it in GitHub Desktop.
Saving running network config to sysconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Hack to quickly save the running network config to sysconfig | |
DEV=eth0 | |
IPDATA=`ip addr show dev $DEV | tr -s " " | grep -m 1 inet | cut -d " " -f 3` | |
IP=`echo $IPDATA | cut -d "/" -f 1` | |
NM=`echo $IPDATA | cut -d "/" -f 2` | |
MAC=`ip addr show dev $DEV | tr -s " " | grep 'link/ether' | cut -d " " -f 3` | |
GATEWAY=`ip r | grep default | cut -d " " -f 3` | |
HOSTNAME=`hostname` | |
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$DEV | |
IPADDR=$IP | |
PREFIX=$NM | |
HWADDR=$MAC | |
ONBOOT=yes | |
BOOTPROTO=static | |
EOF | |
cat <<EOF > /etc/sysconfig/network | |
GATEWAY=$GATEWAY | |
HOSTNAME=$HOSTNAME | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment