на главную | войти | регистрация | DMCA | контакты | справка | donate |      

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я


моя полка | жанры | рекомендуем | рейтинг книг | рейтинг авторов | впечатления | новое | форум | сборники | читалки | авторам | добавить



3.2.1.3. Configuring networking from the command line

The GUI network configuration tool and NetworkManager both work well for desktop users, but when you're logged in to a server that is a few time zones away or need to make a fast change, it's useful to be able to configure networking from the command line.

The main interface configuration command is ifconfig (for interface configuration ). Executed by itself, it displays the basic configuration of active interfaces:

$ /sbin/ifconfig

eth0 Link encap:Ethernet HWaddr 00:0D:56:33:D7:18

      inet addr:172.16.97.100 Bcast:172.16.97.255 Mask:255.255.255.0

      inet6 addr: fe80::20d:56ff:fe33:d718/64 Scope:Link

      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

      RX packets:289 errors:0 dropped:0 overruns:0 frame:0

      TX packets:228 errors:0 dropped:0 overruns:0 carrier:0

      collisions:0 txqueuelen:1000

      RX bytes:45844 (44.7 KiB) TX bytes:27193 (26.5 KiB)

      Interrupt:177


lo    Link encap:Local Loopback

      inet addr:127.0.0.1 Mask:255.0.0.0

      inet6 addr: ::1/128 Scope:Host

      UP LOOPBACK RUNNING MTU:16436 Metric:1

      RX packets:2258 errors:0 dropped:0 overruns:0 frame:0

      TX packets:2258 errors:0 dropped:0 overruns:0 carrier:0

      collisions:0 txqueuelen:0

      RX bytes:2884024 (2.7 MiB) TX bytes:2884024 (2.7 MiB)


The two interfaces displayed here are eth0, the first Ethernet interface, and lo, the loopback interface used when a client and a server that are both on the local machine need to communicate. For each interface, the information displayed includes the IP version 4 address ( inet addr ), IP version 6 address ( inet6 addr ), netmask ( Mask ), status flags (such as UP and RUNNING ), and transmit, receive, and error statistics.

You can narrow down the report to a single interface by specifying that interface name as an argument:

$ /sbin/ifconfig eth0

eth0 Link encap:Ethernet HWaddr 00:0D:56:33:D7:18

       inet addr:172.16.97.100 Bcast:172.16.97.255 Mask:255.255.255.0

       inet6 addr: fe80::20d:56ff:fe33:d718/64 Scope:Link

       UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

       RX packets:331 errors:0 dropped:0 overruns:0 frame:0

       TX packets:261 errors:0 dropped:0 overruns:0 carrier:0

       collisions:0 txqueuelen:1000

       RX bytes:49667 (48.5 KiB) TX bytes:32047 (31.2 KiB)

       Interrupt:177


To see both active and inactive interfaces, use the -a option:

$ /sbin/ifconfig -a

eth0 Link encap:Ethernet HWaddr 00:0D:56:33:D7:18

...(Lines snipped)...

lo Link encap:Local Loopback

...(Lines snipped)...

sit0 Link encap:IPv6-in-IPv4

      NOARP MTU:1480 Metric:1

      RX packets:0 errors:0 dropped:0 overruns:0 frame:0

      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

      collisions:0 txqueuelen:0 

      RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)


wlan0 Link encap:Ethernet HWaddr 00:0C:2D:00:2B:DB

       BROADCAST MULTICAST MTU:1500 Metric:1

       RX packets:0 errors:0 dropped:0 overruns:0 frame:0

       TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

       collisions:0 txqueuelen:1000

       RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)


In this case, there are two interfaces here that didn't show up when ifconfig was run without the -a argument: sit0 , used for IPv6 tunneling, and wlan0 , a Wi-Fi (802.11a/b/g) interface.

ifconfig is also used to configure interfaces. The wlan0 interface can be given an IP address, broadcast address, netmask, and state ( up or down ):

# ifconfig wlan0 up 192.168.9.37 netmask 255.255.255.0 broadcast 192.168.9.255

# ifconfig wlan0

wlan0 Link encap:Ethernet HWaddr 00:0C:2D:00:2B:DB

        inet addr:192.168.9.37 Bcast:192.168.9.255 Mask:255.255.255.0

        inet6 addr: fe80::20c:2dff:fe00:2bdb/64 Scope:Link

        UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

        RX packets:1 errors:0 dropped:0 overruns:0 frame:0

        TX packets:18 errors:0 dropped:0 overruns:0 carrier:0

        collisions:0 txqueuelen:1000

        RX bytes:268 (268.0 b) TX bytes:2922 (2.8 KiB)


In almost all cases, the broadcast address can be left out because it can be determined from the IP address and netmask. The netmask can also be omitted if it is the default value for the network class indicated by the IP address. Table 3-1 lists the standard netmasks.

Although the use of network classes has been made obsolete by the introduction and widespread use of classless interdomain routing (CIDR), the network class values are still used to determine the default netmask. This generates the correct value for most private networks. 

Table 3-1. Netmasks by IP address class (not including Multicast addresses)

First octet of IP address Example Network class Netmask Number of IP addresses in subnet
0127 3.15.97.4 A 255.0.0.0 16,777,216
128191 132.2.2.9 B 255.255.0.0 65,536
192255 204.99.3.8 C 255.255.255.0 256

The up argument is also unnecessary if an IP address is being specified.

The previous command can therefore be written much more simply:

# ifconfig wlan0 192.168.9.37

# ifconfig wlan0

wlan0 Link encap:Ethernet HWaddr 00:0C:2D:00:2B:DB

       inet addr:192.168.9.37 Bcast:192.168.9.255 Mask:255.255.255.0

       inet6 addr: fe80::20c:2dff:fe00:2bdb/64 Scope:Link

       UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

       RX packets:1 errors:0 dropped:0 overruns:0 frame:0

       TX packets:18 errors:0 dropped:0 overruns:0 carrier:0

       collisions:0 txqueuelen:1000

       RX bytes:268 (268.0 b) TX bytes:2922 (2.8 KiB)


3.2.1.2. Using GNOME NetworkManager | Fedora Linux | 3.2.1.3.1. Configuring wireless networks from the command line