Network Configuration files of fedora and ubuntu

Source: Internet
Author: User
1. to create a Linux server, the network configuration file of the fedora system should first understand the meaning of the configuration file related to network services in the Linux environment and how to configure security. In Linux, TCP/IP networks are configured through several text files. you may need to edit them...

1. network configuration file of the fedora system

To create a Linux server, you must first understand the meaning of the configuration files related to network services in the Linux environment and how to configure security. In Linux, the TCP/IP network is configured through several text files. you may need to edit these files to complete networking, the following describes several basic TCP/IP network configuration files.
1./etc/sysconfig/network-scripts/ifcfg- File
In RedHat, the configuration file for the system network device is saved in the/etc/sysconfig/network-scripts directory, the ifcfg-eth0 contains the configuration information for the first Nic, the ifcfg-eth1 contains the configuration information for the second Nic. At startup, the system reads the configuration file to determine whether or not a Nic is started and how to configure it.
The following is an example of the/etc/sysconfig/network-scripts/ifcfg-eth0 file:

DEVICE = eth0
HWADDR = 00: e0: 4c: fe: bb: f5
ONBOOT = yes
BOOTPROTO = none
USERCTL = yes
PEERDNS = yes
IPV6INIT = no
NM_CONTROLLED = yes
TYPE = Ethernet
NETMASK = 255.255.255.0
IPADDR = 192.168.0. [ip]
GATEWAY = 192.168.0.1
DNS1 = 202.96.128.68
DNS2 = 202.96.128.20.

If you want to manually modify the network address or add a new network connection, you can modify the ifcfg- Or create a new file.
DEVICE = Indicates the name of the physical device.
IPADDR = indicates the IP address assigned to the NIC.
NETMASK = Indicates the subnet mask.
BROADCAST = indicates the BROADCAST address.
ONBOOT = yes/no whether the card is activated at startup
BOOTPROTO = none: no startup protocol required
Bootp: Use the bootp protocol
Dhcp: Use the dhcp protocol.
GATEWAY = indicates the default GATEWAY.
MACADDR = Specifies a MAC address.
USERCTL = yes/no whether non-root users are allowed to control the device

2./etc/resolv. conf file
File/etc/resolv. conf to configure the DNS client. it contains the DNS server address and domain name search configuration. each line should contain one keyword and one or more parameters separated by spaces. The following is an example File:
Search wuxp.com
Nameserver 192.168.0.1
Nameserver 192.168.0.2

Search wuxp.com: when a host name that does not include a full domain name is provided, add the suffix wuxp.com after the host name; nameserver: indicates that the host specified by this address is the domain name server when the domain name is resolved. The domain name server is queried according to the order in which the file appears. Therefore, the most reliable server should be provided first. Currently, up to three name servers are supported.

DNS can be set directly in/etc/sysconfig/network-scripts/ifcfg-eth0, as shown in the example at the beginning of the article:

PEERDNS = yes

DNS1 = 202.96.128.68

3./etc/sysconfig/network file
This file is used to specify the network configuration information on the server. The following is an example:
NETWORK = yes
RORWARD_IPV4 = yes
HOSTNAME = server.wuxp.com
GAREWAY = 192.168.0.1
GATEWAYDEV = eth0

NETWORK = yes/no whether the NETWORK is configured
FORWARD_IPV4 = yes/no whether IP forwarding is enabled
HOSTNAME = Indicates the host name of the server.
GAREWAY = indicates the IP address of the network gateway.
GAREWAYDEV = Indicates the gateway device name, for example, eth0

4./etc/hosts file
When the machine starts, before the DNS can be queried, the machine needs to query the matching of some host names to IP addresses. The matching information is stored in the/etc/hosts file. Without a domain name server, all network programs on the system query the file to resolve the IP address corresponding to a host name.
The following is an example of a/etc/hosts file:
127.0.0.1 Localhost server.wuxp.com
192.168.0.3 station1.wuxp.com

The leftmost column is the host IP information, and the middle column is the host name. All the columns that follow are aliases of the host.

Network Configuration example:

You can enter/etc/sysconfig/network-scripts. Locate ifcfg-eth0. edit it as follows:
DEVICE = eth0
ONBOOT = yes
BOOTPROTO = static
IPADDR = 10.9.100.221 (the fixed ip address you need)
NETMASK = 255.0.0.0
GATEWAY = 10.20.255.254
If you need to dynamically allocate IP addresses
DEVICE = eth0
ONBOOT = yes
USERCTL = yes
BOOTPROTO = dhcp

After that:/etc/rc. d/init. d/network restart or/etc/init. d/network restart.

 

II. ubuntu network configuration file

The network configuration files of Ubuntu mainly include the following:


IP address configuration file:/etc/network/interfaces
After it is enabled, you can set DHCP or manually set static IP addresses. Auto eth0 in front to enable automatic Nic mounting.

1. configure the NIC in DHCP mode

Edit the file/etc/network/interfaces:
Sudo vi/etc/network/interfaces

Replace eth0 with the following rows:
# The primary network interface-use DHCP to find our address
Auto eth0
Iface eth0 inet dhcp

Run the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart
You can also enter the following command in the command line to obtain the address.

Sudo dhclient eth0

2. configure a static IP address for the NIC

Edit the file/etc/network/interfaces:

Sudo vi/etc/network/interfaces

Replace eth0 with The following rows: # The primary network interface
Auto eth0
Iface eth0 inet static
Address 192.168.3.90
Gateway 192.168.3.1
Netmask 255.255.255.0

Replace the preceding IP address and other information with your own. use the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart

3. set the second IP address (Virtual IP address)

Edit the file/etc/network/interfaces:

Sudo vi/etc/network/interfaces

Add the following lines to the file:
Auto eth0: 1
Iface eth0: 1 inet static
Address 192.168.1.60
Netmask 255.255.255.0
Network x. x
Broadcast x. x
Gateway x. x

Fill in all information such as address, netmask, network, broadcast, and gateways according to your situation.
Run the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart

Host name configuration command (/bin/hostname)

Run the following command to view the host name of the current host:

Sudo/bin/hostname

Run the following command to set the host name of the current host:

Sudo/bin/hostname newname

When the system starts, it reads the host name from/etc/hostname.


DNS configuration file

First, you can add some host names to/etc/hosts and the IP addresses corresponding to these host names. this is a simple static query on the local machine.

To access the DNS server for query, you need to set the/etc/resolv. conf file.
Sudo vi/etc/resolv. conf

Nameserver 202.96.128.68

Nameserver 61.144.56.101

Nameserver 192.168.8.220

/Reset the network to enable new settings

Sudo/etc/init. d/networking restart

OK


If you like to use other notepad editors such as gedit, replace vi in the command with gedit.

From: acmfly blog

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.