- CentOS 6.3 64bit Plain
- Ubuntu 12.04 64bit Plain
Last active
August 29, 2015 14:00
-
-
Save tily/11394499 to your computer and use it in GitHub Desktop.
ニフティクラウドの VLAN オプションで固定 IP アドレスを自動で振る起動時スクリプト (Redhat 系, Debian 系 OS 向け)
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 | |
PRIVATE_IP='192.168.1.1' # ここに振りたい IP を書く | |
PRIVATE_MASK='255.255.255.0' # ここにネットマスクを書く | |
is_redhat() { | |
[ -e '/etc/system-release' ] | |
} | |
is_debian() { | |
[ -e '/etc/debian_version' ] | |
} | |
configure_redhat_network () { | |
cat << _EOF_ > /etc/sysconfig/network-scripts/ifcfg-eth1 | |
DEVICE=eth1 | |
ONBOOT=yes | |
BOOTPROTO=static | |
IPADDR=$PRIVATE_IP | |
NETMASK=$PRIVATE_MASK | |
_EOF_ | |
} | |
configure_debian_network () { | |
cat << _EOF_ > /etc/network/interfaces | |
auto lo | |
iface lo inet loopback | |
auto eth0 | |
iface eth0 inet dhcp | |
auto eth1 | |
iface eth1 inet static | |
address $PRIVATE_IP | |
netmask $PRIVATE_MASK | |
_EOF_ | |
} | |
restart_redhat_network () { | |
service network restart | |
} | |
restart_debian_network () { | |
/etc/init.d/networking restart | |
} | |
if is_redhat | |
then | |
configure_redhat_network | |
restart_redhat_network | |
elif is_debian | |
then | |
configure_debian_network | |
restart_debian_network | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment