Linux Network configuration

Source: Internet
Author: User

Network hardware

Linux can use any network hardware that has a driver. Linux drivers are compiled into the kernel individually or as loadable modules. The Linux kernel supports many popular NICs by default. When selecting network hardware, it is best to always use the devices listed in the Hardware Compatibility List (see Resources for links). Also use the latest Linux distributions.

In general, if you are using compatible network hardware, the network card will be automatically recognized when you install the system. You can use ifconfig commands to check the network hardware on your system. By default, the ifconfig active network device is displayed. Add a switch to this command to -a see all the devices.

Listing 1. Using Ifconfig
refname:ifconfig-a[[email protected] root]# ifconfig-a eth0 Link encap:Ethernet HWa DDR 00:09:6b:60:8b:1e inet addr:9.41.209.160 bcast:9.41.209.255 mask:255.255.255.0 up broadcast RUNNIN          G multicast mtu:1500 metric:1 RX packets:47255 errors:0 dropped:0 overruns:0 frame:0 TX packets:32949 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:22140365 (          21.1 MB) TX bytes:13519623 (12.8 mb) interrupt:11 Base address:0xf000lo Link encap:local Loopback inet addr:127.0.0.1 mask:255.0.0.0 up LOOPBACK RUNNING mtu:16436 metric:1 RX packets:1308081 errors          : 0 dropped:0 overruns:0 frame:0          TX packets:1308081 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:183376967 (174.8 MB) TX bytes:183376967 (174.8 MB) 

In the above list, there is only one NIC in the system, identified as eth0. The lo adapter is a loopback (Lookback) that is used by Linux to communicate with itself. Further discussion of the commands will be followed ifconfig .

Network device Name

The Linux network device is assigned an alias, which consists of a descriptive abbreviation and a number. The first device of some type is numbered 0, and other devices are numbered 1, 2, 3, and so on. The following conventions are used when naming devices. This information is excerpted from the Linux Network Administrator's Guide (see the links in resources at the end of this article).

    • Eth0, eth1 ...
      These are the Ethernet card interfaces. They are used for most Ethernet cards, including many parallel port Ethernet cards.
    • TR0, TR1 ...
      These are token ring NIC interfaces. They are used for most token ring NICs, including non-IBM-produced NICs.
    • S10, S11 ...
      These are SLIP interfaces. The slip interface is associated with a serial line, which is the order in which they are assigned to SLIP.
    • Ppp0, Ppp1 ...
      These are the PPP interfaces. Just like the SLIP interface, once the PPP interface is converted to PPP mode, it is associated with the serial line.
    • Plip0. Plip1 ...
      These are the PLIP interfaces. The PLIP interface transmits IP datagrams through a parallel line. These interfaces are assigned by the PLIP driver at system startup and are mapped to parallel ports. In the 2.0.x kernel, there is a direct relationship between the device name and the I/O port of the parallel port, but in the newer version of the kernel, the device names are assigned sequentially, just like SLIP and PPP devices.
    • Ax0, Ax1 ...
      These are the ax.25 interfaces. AX.25 is the main protocol used by amateur radio operators. The ax.25 interface is distributed and mapped in a similar way to SLIP devices.

There are many other types of interfaces that can be used with other network drivers. We've only listed some of the most common ones.

Now that Ethernet is the most common configuration, here's a focus on it. For more information about other kinds of connections, see resources at the end of this article.

Analysis and monitoring tools

Linux comes with a number of tools to monitor network tasks.

Ifconfig
We used the command above ifconfig to see the status of the Ethernet card. However, ifconfig you can also configure the device and report on the device. Suppose you want to set up a temporary network configuration for testing. You can use the tools in the release version to edit the configuration, but be aware that after testing is complete, all settings are restored back. By using it ifconfig , we can quickly configure the network card without affecting the saved settings:

ipconfig eth0 192.168.13.13 netmask 255.255.255.0 up

The above command uses a class C IP address to set the eth0 to address 192.168.13.13 and ensures that it runs correctly.

Ipconfig eth0 down

The above command turns off the eth0 device. For ifconfig full details on use, see the info ifconfig page.

Ifup/ifdown
To use a saved configuration to activate and disable network devices, use ifup and respectively ifdown .

# Bring up eth0 using the saved configuration          
Ifup eth0

# Shut down eth0
Ifdown eth0

Netstat
Use netstat the console commands to output network connections, routing tables, interface statistics, spoofing connections, and multicast members. netstathas multiple command-line switches to control its functionality. Here are some of the commonly used switches:

Output Network Status
netstat -p Displays the PID or name of the program to which each socket belongs
netstat -a Simultaneous display of both listening and non-listening sockets
netstat -t Show TCP connections
netstat -u Show UDP connections
netstat -e Show additional information, use this option two times to get the most detailed information

Here's netstat -tp an example:

Listing 2. Using netstat
[[email protected] root]# netstat-tpactive Internet connections (w/o servers) Proto recv-q send-q Local Address Foreign Address statepid/program nametcp 0 0 localhost.localdo:29000 *:* LIST EN2389/ATTVPNCTLTCP 0 0 *:10000 *:* listen5945/perltcp 0 0 *:x                     *:* listen1120/xtcp 0 0 *:ftp *:* LISTEN724/XINETDTCP 0 0 *:ssh *:* listen710/sshdtcp 0 0 *                     : IPP *:* listen797/cupsdtcp 0 0 *:505 *:*       Listen1043/rcdtcp 0 0 Localhost.localdoma:ipp localhost.localdo:32772 established797/cupsdtcp 0 0 sig-9-65-39-140.m:44916 sdoprods2.austin.i:1352 time_wait-tcp 0 0 10.100.100.101:33020 64.12.29.100 : 5190 ESTABLISHED1433/gaimtcp 0 0 localhost.localdo:44954 Localhost.localdoma:ipp time_wait-tcp 0 0 Localhost.locald o:44955 Localhost.localdoma:ipp time_wait-tcp 0 0 localhost.localdo:44897 Localhost.localdoma:ipp TIME_WAIT-TC P 0 0 localhost.localdo:44902 Localhost.localdoma:ipp time_wait-tcp 0 0 localhost.localdo:44903 Lo       Calhost.localdoma:ipp time_wait-tcp 0 0 localhost.localdo:44900 Localhost.localdoma:ipp time_wait-tcp 0 0 localhost.localdo:44901 Localhost.localdoma:ipp time_wait-tcp 0 0 10.100.100.101:44888 cs9336-61.au STIN.R:POP3 time_wait-tcp 0 0 localhost.localdo:32772 Localhost.localdoma:ipp ESTABLISHED1246/GNOME-CUPS-MANTC P 1 0 localhost.localdo:32774 Localhost.localdoma:ipp close_wait1246/gnome-cups-mantcp 0 0 10.100. 100.101:33019 cs46.msg.sc5.yahoo:5050 established1433/gaimtcp 0 0 sig-9-65-39-140.m:35061 D03nm119.boulder. i:1352 Close_wait1720/wiNeservertcp 0 0 10.100.100.101:33021 64.12.30.4:5190 established1433/gaim 

I use commands most often netstat to view connections in a LISTEN or established state. LISTEN is a service on the system that accepts connections from other machines. Established is the active connection between your machine and other machines. Make sure that you know all the LISTEN programs that are running. If you see something that is not recognized, it may be a security concern. netstathas many options. At the command line, type info netstat to get the details of the command.

Route
routeConsole commands allow you to display and manipulate IP routing tables.

Listing 3. Using the route
[Email protected] plugins]# route|grep-v ipseckernel IP routing tabledestination     Gateway         genmask         Flags Metric Ref use    Iface204.146.24.42   10.100.100.1    255.255.255.255 UGH   0      0        0 eth110.100.100.0    *               255.255.255.0   U     0      0        0 eth1127.0.0.0       *               255.0.0.0       U     0      0        0 lodefault         10.100.100.1    0.0.0.0         UG    0      0        0 eth1

Running without a command-line switch route displays the current routing table. You can use route very fine-grained modifications to the routing table.

Route add default GW 10.10.10.1

The above command adds a default route (it will be used if no other route matches). All groupings using this route will pass through the gateway "10.10.10.1". The device that will actually be used for that route depends on how we reach "10.10.10.1"-the static route to "10.10.10.1" must be pre-set.

Route add-net 192.56.76.0 netmask 255.255.255.0 Dev eth0

The above command adds a route through "eth0" to network 192.56.76.x. The class C netmask modifier is not actually necessary because 192.* is a class C IP address. The word "dev" can also be omitted here.

Linux Network configuration

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.