My first interaction with Linux was about six years ago. Then it was some kind of freshly eaten
Red Hat , which my friend and I were able to install, but we didn’t manage to enter it.
However, the article is not about that. Later, almost all the Linux distributions went through my hands and head, and everywhere I noticed my approaches to auto-tuning the network. And in this series of articles I will try to highlight the most popular ones. I hope they will be useful to those users who still click on the buttons and tick the graphical settings managers, but already understand that this is not true :)
Perhaps these articles will be informative and those who (not from a lot of knowledge) write their own network management scripts and put them in some rc.local
So, in the first part we will talk about the family number one, one of the most extensive in terms of the number of distributions,
Red Hat based .
This includes, for example, the distributions currently used, such as:
- Fedora
- RHEL / CentOS
- Mandriva
- ASPLinux
Service scripts for network configuration and the config files themselves in these distributions are traditionally stored in the / etc / sysconfig / network-scripts / directory
There you will find several ifup- * scripts and as many ifdown- * which, respectively, raise or lower a certain type of interface, as well as ifcfg- * (an asterisk is the name) where the settings of these interfaces are stored.
If the network is not yet configured, you will find ifcfg-lo, which describes the loopback interface. In my hand at
Fedora Core 7, this file looks like this: (comments from the file have been deleted)
')
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 options listed here are required. Often, to specify an interface, you only need to specify IPADDR and NETMASK. The DEVICE parameter is required if you want the name of the script after “ifcfg-” to contain not another interface name, but some other word. Here you can also specify such parameters as GATEWAY, BOOTPROTO (static or dhcp), HWADDR (if you want to change the mac-address of the interface) and so on. The full list of possible parameters depends on the type of interface being lifted and the distribution. And, given the scarcity of official information, it can be recognized and known only by shoveling scripts.
Such config files can set various ppp-interfaces, ip-tunnels, vlans and so on.
The following example shows the configuration of an ipip tunnel (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, having the address 172.16.0.2, create a tunnel with the machine 192.168.0.1, specifying TTL = 255, and assign the tunnel address to 10.0.0.2 peer 10.0.0.1.
Not everyone knows that in addition to ifcfg- * files, the corresponding rule- * and route- * files can be placed in the same directory.
They are needed, respectively, to prescribe the routing rules and the routes themselves (
ip rule, ip route
), for example, when using
source-policy routing .
For the above tunnel, these files may look like this.
rule-tun0:from 10.0.0.2 lookup mytable
route-tun0:default dev tun0 table mytable
192.168.0.0/24 dev tun0
Having created these files, we relieve ourselves of the headache that the corresponding rules and routes are created and deleted when the interface is raised and lowered, respectively.
Another interesting feature is the automatic creation of aliases. If you have an eth0 interface with the address 192.168.0.1, and you want to also hang 192.168.0.2, then it is enough to create a file ifcfg-eth0: 1, where to write in addition to the above parameters (IPADDR, NETMASK and so on), another one - REALDEVICE = eth0.
If suddenly there is a need to create a large number of aliases, and you don’t want to create separate files for each, then there is a way out: ifcfg-eth0-range can save us, which can look 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 addresses from 192.168.0.5 to 192.168.0.15.
And finally, it is impossible not to mention the directories ifup.d and ifdown.d, which lie there (in / etc / sysconfig / network-scripts).
You can place your files in these directories that will be executed when the interface is raised and lowered. One parameter will be passed to your scripts. $ 1 is the name of the interface that was raised or lowered.
Having a network configured according to these principles, you can always raise / lower a separate interface with the command ifup name (ifdown name), where name is your interface. To reload the entire network, just dial service network reload.
The next part will be devoted not to the family, but to one distribution kit - Alt Linux. Despite its direct RedHat roots, the developers almost completely re-wrote the entire network management system, which received the name etcnet and deserved (in my opinion) more attention :)