Network settings in linux

Source: Internet
Author: User
Linux network settings-Linux Enterprise Application-Linux server application information. For more information, see. 1. ip address Modification

Manually modify the/etc/sysconfig/network-scripts/ifcfg-eth0 File

Vi open ifcfg-eth0 files

Original content:

DEVICE = eth0
BOOTPROTO = dhcp
HWADDR = 00: 03: 47: 2C: D5: 40
ONBOOT = yes
TYPE = Ethernet



Changed:

DEVICE = eth0
BOOTPROTO = static
IPADDR = 192.168.1.223

NETMASK = 255.255.255.0
GATEWAY = 192.168.1.1

NETWORK 192.168.1.0

BROADCAST 192.168.1.255

HWADDR = 00: 0uu3: 47: 2C: D5: 40
ONBOOT = yes
TYPE = Ethernet

2. Multiple ip addresses for a single Nic

For the first network device of the network, the configuration file name is generally ifcfg-eth0 if you need to bind one more IP address for the first network device, you only need to create a file named ifcfg-eth0: 0 in the/etc/sysconfig/network-scripts directory, the content sample is:
DEVICE = "eth0: 0"
IPADDR = "192.168.1.21"
NETMASK = "255.255.255.0"
ONBOOT = "yes"
If you need to bind another IP address, you only need to add the file name to the eth0: x of the DEVICE in the file. Start with 0. LINUX supports up to 255 IP aliases.

3. Multiple NICs with a single ip Address

You can use multiple NICs to create a network card with the same IP address. The Trunking and etherchannel technologies already exist in sun and cisco. in linux, these technologies are called bonding. Because bonding is included in kernel 2.4.x, you only need to select Bonding driver support in network device options during compilation. Then, recompile the core, restart the computer, and execute the following command:
Ismod bonding
Ifconfig eth0 down
Ifconfig eth1 down
Ifconfig bond0 ipaddress
Ifenslave bond0 eth0
Ifenslave bond0 eth1

Now the two NICs work like one, which can improve data transmission between cluster nodes. It is best to write these statements as a script, which is then called by/etc/rc. d/rc. local or/etc/conf. d/local. start to take effect immediately after the machine is started.

Bonding is a good choice for Servers. When there is no Gigabit Nic, using two or three 100 m NICs as bonding can greatly increase the bandwidth between servers and switches. However, you need to set the two ports mapped to the same Virtual Interface on the vswitch to connect to the bonding Nic.

4. static IP/MAC binding

Create the/etc/ethers file, which contains the correct IP/MAC ing. The format is as follows:

192.168.2.32 08: 00: 4E: B0: 24: 47

Then add arp-f to/etc/rc. d/rc. local.

5. dns settings

In Linux, there are two files used to declare where the system looks for a database for name resolution. The/etc/host. conf file is used by the libc library of version 5, while/etc/nsswitch. conf file is used by version 6 (glibc ). The problem is that some programs use one of them, while some use another. Therefore, it is necessary to correctly configure both files.
1./etc/host. conf

The/etc/host. conf file specifies how to resolve the host name. Linux uses the parser library to obtain the IP address corresponding to the host name. The following is the default/etc/host. conf content after RedHat is installed:
[Root @ linpc root] # cat/etc/host. conf

Order hosts, bind
Here, order specifies the query order of the host name. Its parameters are the query methods separated by commas.

2./etc/nsswitch. conf

/Etc/nsswitch. the conf file is developed by SUN and is used to manage the order of query of multiple configuration files in the system, and/etc/host. it provides more functions than the conf file. /Etc/nsswitch. except for the annotator starting with # In conf, all comments start with a keyword, followed by a colon, followed by a blank space, followed by a list of methods, these methods can provide the system with information related to the keyword that begins with a line, and the system will query in order of their order. Each keyword is the name of the/etc file that can be controlled by/etc/nsswith. conf in the/etc/directory. In the DNS configuration, add the DNS option after the hosts line in the file:
Group: files nis
# Hosts: db files nisplus nis dns

Hosts: files dns

3./etc/resolv. conf

Modify it.

Example:

Search localdomain.com
Nameserver 210.34.0.14
Nameserver 210.34.0.2

Nameserver indicates the IP address of the DNS server. There can be multiple rows of nameserver, each with an IP address. The following nameserver is queried only when the first nameserver does not respond.
Domain (optional) declares the host domain name. Many programs use it, such as the mail system. DNS queries are also required for hosts without domain names. If no domain name exists, the host name will be used and all content before the first vertex (.) will be deleted.

4. Prevent dhcp from automatically modifying dns

Change the configuration file of the DHCP Client and append our settings at specific links.

Linux (Ubuntu Dist .):

Add the following settings to/etc/dhcp3/dhclient. conf: prepend domain-name-servers , ;

FreeBSD:

Add the following settings to/etc/dhclient. conf: prepend domain-name-servers , ;

6. Restart the service.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.