12, the network access configuration process:
Linux is now generally in the boot will automatically configure the network card (wired network card or wireless network card), as long as the direct set of its IP (can use DHCP), subnet mask, the default route (that is, the default gateway), and sometimes to set up DNS, you can access the Internet. These configurations now have a graphical user interface, typically in the upper-left corner of the system bar, which opens directly, and you see a wired or wireless connection setting interface. This is mainly about configuring network access through commands and configuration files.
(1) Configuration of files involved:
Redhat/fedora:
Host name, default route:/etc/sysconfig/network
Network card IP address, netmask, broadcast address:/etc/network_scripts/ifcfg-ifname (e.g. Ifcfg-eth0)
Suse:
Host name, IP address, netmask, etc.:/etc/rc.config
Default route:/etc/route.conf
Debian/ubuntu:
Host Name:/etc/host/hostname
Network card IP address, netmask, default route:/etc/network/interfaces
(2) Assign a unique hostname and IP address: Assign the host name with the hostname command, assign the DNS domain name with the DnsDomainName command, and now most systems typically assign full names, both host names and DNS domain names. The hostname and DnsDomainName commands are typically executed from the startup script at system startup to get the host full name, and you can use these two commands if you want to change the hostname later. Network card IP address can be manually assigned, that is, directly in the corresponding files listed above set up static IP, if the use of dynamic IP, DHCP automatically allocated. Many sites now use the LDAP database directly to manage their host names and IP address assignment transactions.
(3) Configure network interface parameters: Use the ifconfig command to set the parameters of the network interface. Format for Ifconfig interface address options ... such as ifconfig eth0 192.168.1.13 netmask up. Where eth0 is the interface name of the NIC, the mapping relationship between the hardware identification name and the device driver is kept in the/etc/modules.conf, and the loopback interface is lo. Configuring the loopback interface is commonly used ifconfig lo 127.0.0.1 up. Common options:
Netmask: Set the subnet mask for the interface
Broadcast: Set IP broadcast address of interface
Up/down: The interface is started/closed and is turned on by default when this option is not specified.
(4) Configure the negotiation mode and other features of the network interface: using the Mii-tool command, it is used to query or set media-specific parameters such as link rate and full/Half-duplex mode. The-v option can be used to query the state of an interface, for example:
$ sudo mii-tool-v eth0 eth0:negotiated 100basetx-fd flow-control, link OK product Info:vendor 00:aa:00, model Rev 0 Basic Mode:autonegotiation enabled Basic status:autonegotiation complete, link OK capabilities:1000baset-fd 100basetx-f D 100basetx-hd 10baset-fd 10baset-hd advertising:100basetx-fd 100basetx-hd 10baset-fd 10baseT-HD flow-control link partn ER:1000BASET-FD 100basetx-fd 100basetx-hd 10baset-fd 10baset-hd Flow-control
In order to lock this interface in 100mbit/s Full-duplex mode, you can use the command sudo mii-too-force=100basetx-fd eth0. Add this command to the system startup script so that it is always valid so that the NIC automatically locks to 100basetx-fd each time it starts.
(5) Configure static routing: Using the route command, the basic format is
Route add [-net|-host] target [netmask Nm] [GW GW] [metric N] [[Dev] iface]
Route del [-net|-host] target [GW GW] [netmask Nm] [metric N] [[Dev] iface]
Where target is the host address or network address, and if it is a network address, specify a network mask. GW for the first hop gateway, metric is the packet to reach the destination of the number of times required to forward (hop), Dev designated network interface, can be omitted. The Query routing table is available with commands route, NETSTAT-NR, or netstat-r.
(6) Configure the default route: that is, the default gateway, simply add the command route add defalut GW gateway-ip-address to the startup file. However, most systems get the gateway IP address from the configuration file, rather than write the explicit IP address directly to the startup file. The specific configuration items are as follows:
RedHat: Modify the Gateway option in/etc/sysconfig/network.
SUSE: Join a row of default Ip-addr mask interface in/etc/route.conf
Debian/ubuntu: Modify the gateway option in/etc/network/interfaces
(7) Configure DNS: Modify the/etc/resolv.conf file, specify the IP of the DNS server through the nameserver option, and specify the incomplete name to resolve by using the search option. You can use the service switch file/etc/host.conf and/etc/nsswitch.conf to specify the order in which DNS, NIS, and/etc/hosts are referenced, or to completely cancel a service's data source. After network configuration can use Ifdown and ifup to shut down or start network interface, can use sudo/etc/init.d/networking Restart to restart Network service.
13. Configuration instance (take Debian/ubuntu faction for example):
(1) Configure the DHCP address for the network card: for example, enter the following lines in the/etc/network/interfaces (assuming your NIC is eth0):
# The primary network Interface-use DHCP to find we address auto eth0 iface eth0 inet DHCP # specified as DHCP
(2) Configure static IP for the NIC: for example, enter the following lines in/etc/network/interfaces (assuming your NIC is eth0):
# The primary network interface auto eth0 iface eth0 inet static # specified as static address 192.168.3.90 # IP addresses Gateway 192.168.3 .1 # Gateway address netmask 255.255.255.0 # subnet Mask Network 192.168.3.0 # This address represents this network broadcast 192.168.3.255 # broadcast address
(3) Setting a second IP address or virtual IP: We can assign multiple IP addresses to a network interface by using the concepts of "virtual network Interface" or "IP alias". System administrators often use them to allow a single machine to host multiple Web sites. On Linux systems, virtual interfaces are called eth0:0, eth0:1, and so on. For example, enter the following in the/etc/network/interfaces text:
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
Once configured, you should be able to ping this new IP address from other servers on the network.
(4) Set up Ubuntu system hostname: Use command hostname to change the host name of the system, or directly edit/etc/hostname.
(5) Setting up DNS: For example, add the following in/etc/resolv.conf:
Search test.com nameserver 192.168.3.2
Note that after all configuration is complete, do not forget to restart the network service with sudo/etc/init.d/networking restart.