The network configuration is done by the script network.sh (Section 3.2, “/usr/local/config/network.sh”) and by the configuration file network.cfg (Section 3.3, “/usr/local/config/nework.cfg”), 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 the Internet, and the IP of the DB server to which we are going to do port forwarding. This information is stored in the file network.cfg.
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.cfg accordingly and to run the script network.sh:
bash# vi /usr/local/config/network.cfg bash# /usr/local/config/network.sh
However, if we have some standard configurations that are repeated time after time, then it is better to prepare some standard configuration files and use one of them accordingly, like this:
bash# cd /usr/local/config/ bash# cp network.cfg.1 network.cfg bash# ./network.sh
This is what we actually do in order to switch instantly from the first configuration to the second configuration (and back, if needed), do you remember from the story (Section 1.2, “The Story”)?
To check that the network is configured properly, the following commands can be used:
Checking what addresses are assigned to the network interfaces:
bash$ /sbin/ip addr help bash$ /sbin/ip addr ls
Checking the routes:
bash$ /sbin/ip route help bash$ /sbin/ip route ls
#!/bin/bash ### include the configuration file path=$(dirname $0) . $path/network.cfg ### 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
### 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 ### DB server interface DB_IP=192.168.0.10
### 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 ### DB server interface DB_IP=10.10.3.102
### 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 ### DB server interface DB_IP=10.10.3.102
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 ### DB server interface DB_IP=192.168.0.10