Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Wed May 02, 2012 12:22 pm 
Offline
Newbie

Joined: Fri Jan 21, 2011 10:08 am
Posts: 4
Website: http://zachbrowne.com
Just change the variables at the top to your own.

Code:
#!/bin/bash

#  Static Networking Setup for Ubuntu Web Server
#  by Zach Browne - http://zachbrowne.com

# Replace these variables with your own
HOSTNAME=zeus # Ex. server, dev or zeus
HOSTNAME_FQDN=zeus.browne.cm # Ex. server.domain.com, dev.domain.com or zeus.domain.com
TIMEZONE=Central # Central, Eastern, Pacific or Mountain
LINODE_PUBLIC_IP=96.126.124.64
LINODE_SERVER_GATEWAY_IP=96.126.124.1
LINODE_PRIVATE_IP=192.168.147.82
LINODE_DNS_RESOLVER1=72.14.188.5
LINODE_DNS_RESOLVER2=72.14.179.5

# Set time & update server
ln -sf /usr/share/zoneinfo/US/$TIMEZONE /etc/localtime
aptitude update && aptitude -y safe-upgrade

# Setup hosts file
rm /etc/hosts
touch /etc/hosts

cat > /etc/hosts <<EOF
127.0.0.1 localhost.localdomain localhost
$LINODE_PUBLIC_IP $HOSTNAME_FQDN $HOSTNAME
EOF

# Setup static IP
rm /etc/network/interfaces
touch /etc/network/interfaces

cat > /etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
auto eth0 eth0:1
iface eth0 inet static
address $LINODE_PUBLIC_IP
netmask 255.255.255.0
gateway $LINODE_SERVER_GATEWAY_IP
iface eth0:1 inet static
address $LINODE_PRIVATE_IP
netmask 255.255.128.0
EOF

# Remove DHCP
aptitude -y remove dhcpcd

# Add options rotate
rm /etc/resolv.conf
touch /etc/resolv.conf

cat > /etc/resolv.conf <<EOF
search members.linode.com
nameserver $LINODE_DNS_RESOLVER1
nameserver $LINODE_DNS_RESOLVER2
options rotate
EOF

# Install Bind9 to cache Linode's DNS servers.
aptitude -y install bind9

rm /etc/bind/named.conf.options
touch /etc/bind/named.conf.options

cat > /etc/bind/named.conf.options <<EOF
{
directory "/var/cache/bind";
auth-nxdomain no;
forwarders {69.93.127.10;65.19.178.10;75.127.96.10;207.192.70.10;109.74.194.10;};
listen-on-v6 {any;};
};
EOF

# Restart networking
/etc/init.d/networking restart

_________________
[bold]Zach Browne[/bold]
[em]Web Consultant[/em]
[a href=http://zachbrowne.com]zachbrowne.com[/a]


Top
   
PostPosted: Wed May 02, 2012 3:07 pm 
Offline
Senior Member

Joined: Fri Feb 18, 2005 4:09 pm
Posts: 594
zachbrowne wrote:
Code:
aptitude update && aptitude -y safe-upgrade
aptitude -y remove dhcpcd
aptitude -y install bind9


Is "aptitude" a CentOS command? Gentoo? Ubuntu only?

James


Top
   
 Post subject:
PostPosted: Wed May 02, 2012 3:31 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
It's been ages since I installed and configured Bind, but if you run Bind locally, shouldn't resolv.conf point to localhost? Also, aren't Linode's DNS resolvers datacentar-specific?


Top
   
 Post subject:
PostPosted: Wed May 02, 2012 3:40 pm 
Offline
Senior Member

Joined: Mon Dec 07, 2009 6:46 am
Posts: 331
While I'm at it:

* timezone in a static networking script? and US only?
* rm and touch are redundant if you do cat >
* hostname should be taken out of fqdn automatically:

Code:
HOSTNAME=`echo $HOSTNAME_FQDN | awk -F"." '{print $1}'`


Top
   
PostPosted: Wed May 02, 2012 7:53 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
zunzun wrote:
Is "aptitude" a CentOS command? Gentoo? Ubuntu only?

James


The "for Ubuntu Web Server" in the very first comment of the script seems pretty clear to me...

That said, I'm not sure that this script is the greatest idea. A static IP setup requires you to merely update a few config files, not to update packages or uninstall dhcpcd or install bind...


Top
   
 Post subject:
PostPosted: Thu May 03, 2012 10:22 am 
Offline
Senior Newbie

Joined: Fri Apr 15, 2011 6:18 am
Posts: 8
No error checking performed and no trap to stop the script if it encounters a problem. The 'rm' and 'touch' commands would also appear to be useless since you're overwriting the files anyway ( > ).


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group