Network Configuration on Linux through the config files
The first time I met with this operating system about six years ago. Then, as I recall just came out Red Hat, which I tried to install, but we got a nasty surprise, we have failed to enter into it.
But the article is about something else entirely. Later, through my head and hands have passed almost all distributions Linux, and each system had its own approach for the network settings. And in this article I will try to explain the most popular of all. I very much hope that this article will be very useful for users who still click with the mouse on the screen and put a tick in various graphic managers, but are beginning to understand that this is not true =)
Also, maybe this article will be informative, and those users who wrote the scripts for network management, and places his creation in some rc.local
So, first let's talk about the head of the family, one of the most common distributions by number RHB (Red Hat based).
For example, this distribution package also includes systems listed below:
4. RHEL / CentOS
Scripts that are necessary to configure the network and the configuration files themselves in the family of these distributions are placed in the / etc / sysconfig / network-scripts /
There you can find a couple of browser type ifup- * and the same amount ifdown- *, which of course can raise or lower one or the other type of interface, as well as ifcfg- * (where * - file name) that hosts the configuration data interfaces.
If you have not set up a network that can be found there a file ifcfg-lo, which describes the interface loopback. I have at the moment there is Fedora Core 7, the file looks like this:
DEVICE = lo
IPADDR = 127.0.0.1
NETMASK = 255.0.0.0
NETWORK = 127.0.0.0
BROADCAST = 127.255.255.255
ONBOOT = yes
NAME = loopback
Not all of the settings that I have listed here are required. Very often, to set the interface, you can simply specify the IPADDR and NETMASK. Enter the DEVICE parameter is necessary in order if you want to in the name of the script after "ifcfg-" was not the name of the interface, and the other word. Here you can also specify parameters BOOTPROTO (static or dhcp), GATEWAY, HWADDR (this if you want to change the mac-address of the interface), and many others. Full list of all the parameters depends on the type of distribution and lifted interface. Well, if you take into account that official information really is not, it will be possible to find out, if only to shovel all the scripts.
With the help of these configuration files, you can specify PPP interfaces, ip vlan tunnels also, and more
With the help of the following example I will show ipip-tunnel configuration (ifcfg-tun0):
DEVICE = tun0
MY_OUTER_IPADDR = 172.16.0.2
PEER_OUTER_IPADDR = 192.168.0.1
MY_INNER_IPADDR = 10.0.0.2
PEER_INNER_IPADDR = 10.0.0.1
TYPE = IPIP
TTL = 255
In this example, we have the address 172.16.0.2, can make a tunnel with a machine 192.168.0.1, in this case have TTL = 255, on the tunnel assign address 10.0.0.2 peer 10.0.0.1
Few people know that in addition to files ifcfg- * in the same directory, you can put the files corresponding route- * and rule- *
They are used in order to be able to prescribe the routes and routing rules ip route, ip rule, for example while using source-policy routing.
For the tunnel, which I have only just above, these files will look like this.
from 10.0.0.2 lookup mytable
default dev tun0 table mytable
192.168.0.0/24 dev tun0
We'll take all the headache after create these files that will make sure that the appropriate routes and rules can be created and deleted during the raising and lowering interface
There is another pretty interesting opportunity - is to create an alias (automatic). If you have an eth0 interface with the address 192.168.0.1, and still want to hang back and 192.168.0.2, it will be enough to create a file named ifcfg-etho0: 1, insert, which can be in addition to the parameters NETMASK, IPADDR and other, more REALDEVICE = eth0. For some it may be an urgent need to create multiple aliases, and create for each individual files a bit uncomfortable, there is a way: we will ifcfg-eth0-range, which looks like this
IPADDR_START = 192.168.0.5
IPADDR_END = 192.168.0.15
CLONENUM_START = 3
This example will create interfaces eth0: 3-eth0: 13, with the assigned addresses from 192.168.0.5 to 192.168.0.15
And, of course, would be unforgivable to remember directories: ifdown.d and ifup.d, which lie along the same path (/ etc / sysconfig / network-scripts).
In these directories, you can put your own files, they will be carried out during the raising and lowering of the interface. Your scripts to give the $ 1 - is the name of the lowered or raised by the interface. If you have a network that is configured according to these principles, you can always raise or lower the interface with the command ifdown.d name (name - this interface)