3. Network Configuration

The network configuration is done by the script network-setup and by the configuration file network-config , which is included and used by this script (and other configuration scripts as well). The server has two network interfaces, one external (eth0) and one internal (eth1). For the network configuration of the server we need to know the IP and NETMASK of these interfaces, the GATEWAY to internet, and the IP of the CACHE (database) server to which we are going to do port forwarding. This information is stored in the file network-config .

This way of separating the configuration information from the configuration scripts gives us flexibility for changing the configuration quickly and safely. For example, if we need to change the gateway, all we should do is to modify network-config accordingly and to run the script network-setup :

bash# vi /usr/local/config/network-config
bash# /usr/local/config/network-setup

However, if we have some standard configurations that are repeated time after time, then it is better to prepare some standard config files and use one of them accordingly, like this:

bash# cd /usr/local/config/
bash# cp network-config-1 network-config
bash# ./network-setup

3.1. /usr/local/config/network-setup

#!/bin/bash

### include the configuration file
. /usr/local/config/network-config

### set up the links, in  case that they are not up
/sbin/ip link set eth0 up
/sbin/ip link set eth1 up

### flush any existing ip addresses of eth0 and eth1
/sbin/ip address flush eth0
/sbin/ip address flush eth1

### add new addresses
/sbin/ip address add $ETH0_IP/$ETH0_MASK dev eth0
/sbin/ip address add $ETH1_IP/$ETH1_MASK dev eth1

### add a default route
/sbin/ip route add default via $GATEWAY dev eth0                                            

3.2. /usr/local/config/nework-config


### internal interface of the router
GATEWAY=192.168.0.1

### external interface of the web server
ETH0_IP=192.168.0.201
ETH0_MASK=24

### internal interface of the web server
ETH1_IP=192.168.0.200
ETH1_MASK=24

### database server (cache) interface
CACHE_IP=192.168.0.10

3.3. /usr/local/config/network-config-1


### internal interface of the router
GATEWAY=10.10.3.253

### external interface of the web server
ETH0_IP=10.10.3.101
ETH0_MASK=24

### internal interface of the web server
ETH1_IP=10.10.3.100
ETH1_MASK=24

### database server (cache) interface
CACHE_IP=10.10.3.102

3.4. /usr/local/config/network-config-2


### internal interface of the router
GATEWAY=192.168.0.1

### external interface of the web server
ETH0_IP=192.168.0.2
ETH0_MASK=30

### internal interface of the web server
ETH1_IP=10.10.3.100
ETH1_MASK=24

### database server (cache) interface
CACHE_IP=10.10.3.102

3.5. /usr/local/config/network-config-3

This is a configuration used in another network. Suppose that we install and test the server in one network and deploy it in another one. The flexibility of the configuration scripts allows us to do this.


### internal interface of the router
GATEWAY=192.168.0.1

### external interface of the web server
ETH0_IP=192.168.0.201
ETH0_MASK=24

### internal interface of the web server
ETH1_IP=192.168.0.200
ETH1_MASK=24

### database server (cache) interface
CACHE_IP=192.168.0.10