Linux systems generally fall into two main categories: 1, Redhat series: Redhat, Centos, fedora, etc. 2, Debian series: Debian, Ubuntu, etc.
Linux system, TCP/IP network is configured through a number of text files, you need to configure these files to network, the following on the Linux two major types of systems in the basic TCP/IP network configuration file to do the study summary.
The first type of Debian in the Ubuntu system as an example
Ubuntu System Network configuration file has interfaces,resolv.conf and so on.
I. Network interface configuration file:/etc/network/interfaces
1. The contents are as follows:
# The Loopback network interface
Auto Lo#网卡开机自动挂载
Iface Lo inet Loopback
Auto eth0#网卡开机自动挂载, Connection network
Iface eth0 inet static #static表示使用固定ip, DHCP means using dynamic IP
Address 10.1.101.227 #设置ip地址
netmask 255.255.255.0 #设置子网掩码
Gateway 10.1.101.254 #设置网关
Dns-nameservers 10.1.101.51
Modified interfaces use the following command to make the network settings effective :/etc/init.d/networking restart #重启网络
2. Set a second IP address (virtual IP address)
Edit File/etc/network/interfaces
Auto Eth0:1
Iface eth0:1 inet Static
Address 192.168.1.60
Netmask 255.255.255.0
Network x.x.x.x
Broadcast x.x.x.x
Gateway x.x.x.x
Second, DNS configuration file:/etc/resolv.conf
You can first add some host names and IP addresses for these host names in/etc/hosts, which is a simple static query that uses native computers.
To access the DNS server for querying, you need to set the/etc/resolv.conf file.
This file sets the IP address and DNS domain name of the DNS server, which is the configuration file used by the domain name Resolver .
(Domain name resolver: resolver, a library that resolves IP addresses based on host name)
DomainName Domain Name
Search domainname.com #表示提供了一个不包括完全域名的主机时, add domainname.com suffix after host
NameServer x.x.x.x #设置首选DNS, the domain name isresolved using the host specified by this address as the name server, in order to find nameserver.
NameServer x.x.x.x# setting up alternate DNS
Sortlist #对返回的域名进行排序
Make network settings effective :/etc/init.d/networking restart #重启网络
Iii../etc/hosts file
Contains a list of known hosts (on the local network). If the system's IP is not dynamically acquired, it can be used. For simple host name resolution (dot notation), before requesting a DNS or NIS network,/etc/hosts.conf usually tells the resolver to check here first.
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
Iv./etc/host.conf
When DNS domain name resolution and/etc/hosts host table mechanisms exist in the system, the/etc/host.conf determines the host name interpretation order.
Order Hosts,bind #名称解释顺序, order is a keyword that defines the name interpretation first with the native hosts table, and then searches for the Bind name server (DNS) if it cannot be interpreted.
Multi on #允许主机有多个IP地址
Nospoof on #禁止IP地址欺骗
Wu,/etc/services
Internet Network Service file to convert the network service name to a port number/protocol. Read by inetd, Telnet, tcpdump, and some other programs. Each row in the file corresponds to a service that consists of 4 fields, separated by a tab or a space, representing the service name, use port, protocol name, and alias.
Service port/Port type alias $ cat/etc/services |moretcpmux 1/tcp # TCP Port Service Multiplexerecho 7/ Tcpecho 7/udpdiscard 9/tcp sink nulldiscard 9/udp sink nullsystat 11/tcp Usersdaytime 13/tcpdaytime 13/udpnetstat 15/tcpqotd 17/tcp quotemsp 18/tcp # Message Send protocol
VI. Host name configuration file/bin/hostname
Use the command hostname newname to set the new host name
When the system starts, it reads the host name from/etc/hostname
Vii. network-related scripts and commands
/etc/init.d/networking
Initialization script at system startup, when the system starts at a certain level, it is responsible for initializing all first-level configured network interfaces.
Ifconfig command
View the current system network configuration with the Ifconfig command without any parameters:
Eth0: Indicates the network card designator
Lo:linux Internal network loopback address for simulating network behavior
HWADDR: The hardware address of the NIC, which is the MAC address
inet addr: IP address of the network card
Bcast: Broadcast Address
Mask: Subnet Mask
MTU: The Maximum Transmission Unit (Maximum Trassmission UNIT), which identifies the maximum number of packets that can be transmitted by the network interface, this value setting error may cause a network failure.
PX: Data reception from the start of the network until now
TX: Data sent by network from boot to current
Collisions: The situation of network signal conflict
Example of Redhat in the second class of Redhat
Network configuration of the Redhat system
One
Modify IP Address
1. IP configuration file
Modify the IP address profile of the corresponding NIC/etc/sysconfig/network-scripts/ifcfg-<interface-name> file
In Redhat, the configuration file for the system network settings is saved in the/etc/sysconfig/network-scripts directory. Ifcfg-eth0 represents the configuration information for the first NIC, and ifcfg-eth1 represents the configuration information for the second NIC. At startup, the system determines whether a network adapter is started and configured by reading the configuration file.
If you want to manually modify the network address or add a new network connection, you can do so by modifying the corresponding ifcfg-<interface-name> or creating a new file.
The following is the configuration information meaning of/etc/sysconfig/network-scripts/ifcfg-{interface-name}
device={name} #{name} indicates the name of the network card corresponding to the physical device, Eth0 is the first NIC, two NICs or more eth1,eth*
Type=ethernet #网络类型, Ethernet on behalf of Ethernet
onboot=yes/no #系统启动引导时是否激活该网络接口, set to Yes to activate this device
Nm_controlled=yes
Bootproto=none/static/bootp/dhcp # Set the way the network card obtains the IP address , the possible option is NONE,STATIC,BOOTP,DHCP, corresponding to the non-applicable protocol, respectively, Specify IP address statically, obtain IP address via DHCP protocol, obtain IP address via BOOTP protocol
ipaddr={address} #如果设置网卡获得ip地址的方式为静态指定, {addres} represents the IP address assigned to the NIC
NETMASK={mask} #{mask} indicates the network mask corresponding to the NIC
Network ={address} #{address} indicates the net address of the NIC (Can not)
Gateway={address} #{address} default gateway
DNS1=10.1.101.51 #DNS服务配置
broadcast={address} #{address} corresponds to the subnet broadcast address, such as 192.168.0.255(can not)
Macaddr={mac-address} #{mac-address} indicates that a MAC address is specified
Userctl=yes/no # Whether to allow non-root users to control the device
hwaddr=50:e5:49:df:b0:8b # The corresponding network card physical address
Ipv6init=no #IPV6
Ipv6_autoconf=no
2, a single network card binding 2 IP
You only need to create a file named ifcfg-eth0:0 in the/etc/sysconfig/network-scripts directory.
Examples of the content are:
Device= "eth0:0"
Ipaddr= "x.x.x.x"
netmask= "255.255.255.0"
If you need to bind more than one IP address, simply add the file name and the eth0:0 in the device in the file.
Linux can support a maximum of 255 IP aliases.
Second, modify the gateway
Gateway configuration file for /etc/sysconfig/network file
The gateway configuration can also be configured in/etc/sysconfig/network-scripts/ifcfg-eth0.
Network is used to specify the networking configuration information on the server, and the file configuration entry has the following meanings:
Network =yes #表示系统是否使用网络, generally set to Yes, if set to No, you cannot use networks, and many system services programs will not start
Rorward_ipv4=yes
HOSTNAME={hostname} #{hostname} represents the hostname of the server, where the host name corresponds to the hostname set in the/etc/hosts
gareway={address} #{address} Sets the IP address of the gateway for the native connection, for example, the gateway 10.0.0.2
Gatewaydev={device} #{device} represents the device name of the gateway, such as: Eth0
network=yes/no #网络是否被配置
forward_ipv4=yes/no #是否开启IP转发功能
Third, modify the DNS
DNS configuration file for /etc/resolv.conf file
DNS configuration can also be configured in/etc/sysconfig/network-scripts/ifcfg-eth0.
The resolv.conf file is used to configure the DNS client, which contains the DNS server address and domain name search configuration. With Ubuntu configuration. Currently, up to three DNS servers are supported.
NameServer 8.8.8.8 #google域名服务器
NameServer 8.8.8.4 #google域名服务器
Iv../etc/hosts file
At machine startup, before DNS is available for querying, the machine needs to query for some hostname-to-IP address matching. This information is stored in the/etc/hosts file.
In the absence of a domain name server, all network programs on the system resolve the IP address corresponding to a host name by querying the file.
[Email protected] network-scripts]# cat/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.1.101.117 Lxy-nfs lxy-nfs.engine.com
The leftmost is a series of host IP information, with some column hostnames in the middle. Any subsequent columns are aliases for that host.
Five, restart the network configuration method
1. #Service Network Restart
2. #/etc/init.d/network Restart
3, #ifdown eth0
#ifup eth0
4, #ifconfig eth0 down
#ifconfig eth0 up
Vi. Related Orders
Modify IP Address
1. Immediate effect:
#ifconfig eth0 192.168.0.2 netmask 255.255.255.0
2. Restart the system to take effect:
Modify/etc/sysconfig/network-scripts/ifcfg-eth0
To modify the gateway default gateways
1. Immediate effect
#route Add default GW 192.168.0.2 netmask 255.255.255.0
2. Restart the system to take effect:
Modify/etc/sysconfig/network
Modify DNS
Modification of/etc/resolv.conf can be effective immediately after modification.
Modify Host Name
1. Immediate effect
Hostname newname
2, restart the system to take effect
Modify/etc/sysconfig/network
Starting and shutting down the firewall
1. Immediate effect:
#service iptables Start
#service iptables Stop
2. Restart the system to take effect:
#service iptables on
#service iptables off
Summarize Network configuration: Configure IP, Gateway, DNS, and then restart the network.
Linux network-related configuration files