Skip to content

Instantly share code, notes, and snippets.

@hcooper
Created September 14, 2012 08:42
Show Gist options
  • Save hcooper/3720821 to your computer and use it in GitHub Desktop.
Save hcooper/3720821 to your computer and use it in GitHub Desktop.
Saving running network config to sysconfig
#!/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