Linux/redhat Wired Network configuration

Source: Internet
Author: User
Tags nameserver
Ifconfig Configure the Network interface tool introduction;

Ifconfig is a tool used to view, configure, enable, or disable network interfaces, which is extremely common. For example, we can use this tool to temporarily configure the network card IP address, mask, broadcast address, Gateway and so on. It can also be written to a file (such as/etc/rc.d/rc.local), so that when the system is booted, it will read the file and set the IP address for the NIC, but it does not seem to be necessary at this time. The main is that each release version has its own configuration tools, in any case, the host can be added to the network;

Let's take a look at ifconfig usage;

ifconfig View network interface status;

Ifconfig If no parameters are received, the current network interface will be exported;

 [root@localhost ~]# ifconfig eth0 Link encap:ethernet hwaddr 00:c0:9f:94:78:0e inet addr:192.168.1.88 bcast:192.168.1.255 mask:255.255.255.0 inet6 addr:fe80::2c0:9fff:fe94:780e/64 scope:link up BROADC
          AST RUNNING multicast mtu:1500 metric:1 RX packets:850 errors:0 dropped:0 overruns:0 frame:0 TX packets:628 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:369135 (3
          60.4 KiB) TX bytes:75945 (74.1 KiB) interrupt:10 Base address:0x3000 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:57 errors:0 dropped:0 overruns:0 frame:0
          TX packets:57 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 RX bytes:8121 (7.9 KiB) TX bytes:8121 (7.9 KiB) 

Explanation:
Eth0 represents the first network card, where hwaddr represents the physical address of the network card, we can see that the physical address of the current network card (MAC address) is 00:c0:9f:94:78:0e, inet addr is used to represent the IP address of the network card, the IP address of this network card is 192.168. 1.88, broadcast address, bcast:192.168.1.255, mask address mask:255.255.255.0

Lo is the host's return-bad address, which is typically used to test a network program, but does not want the local area network or extranet users to be able to view, only on this host to run and view the network interface used. For example, we assign the httpd server to the bad address, in the browser input 127.0.0.1 will be able to see your Web site. But only you can see, the other LAN hosts or users do not know;

if we want to know all the network interface of the host, please use the following command; [Root@localhost ~]# Ifconfig-a

if we want to see a port, for example, we want to see the status of eth0, we can use the following method; [Root@localhost ~]# ifconfig eth0


Ifconfig Configuration Network interface;

Ifconfig can be used to configure the IP address, mask, gateway, physical address of the network interface, etc. it is worth saying that the IP address is specified with Ifconfig for the network card, which is only used to debug the Web, and does not change the system's configuration file about the NIC. If you want to fix the IP address of the network interface, there are currently three methods: one is to modify the IP address through the various distribution and version-specific tools; the other is to modify the network interface configuration file directly; The third is to modify specific files, add ifconfig instructions to specify the IP address of the network card, For example, in Redhat or Fedora, the Ifconfig's name is written into/etc/rc.d/rc.local file;

ifconfig How to configure network ports:

The Ifconfig tool configures the network interface by using the parameters of the instruction to achieve the goal, we only say the most commonly used parameters; Ifconfig network port IP address HW <HW> MAC address netmask mask address broadcast broadcast address [Up/down ]

* Example One:
For example, we use Ifconfig to debug the address of the ETH0 network card [root@localhost ~]# ifconfig eth0 down
[Root@localhost ~]# ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0
[Root@localhost ~]# ifconfig eth0 up
[Root@localhost ~]# ifconfig eth0
Eth0 Link encap:ethernet hwaddr 00:11:00:00:11:11
inet addr:192.168.1.99 bcast:192.168.1.255 mask:255.255.255.0
Up 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)
Interrupt:11 Base address:0x3400

Note: Let us explain the above example;

The first line: Ifconfig eth0 down means that if eth0 is active, it's down. This command equates to Ifdown eth0;
Second line: Use Ifconfig to configure eth0 IP address, broadcast address and netmask;
Third line: Activates the eth0 with ifconfig eth0 up; This command is equivalent to Ifup eth0
Line four: Use ifconfig eth0 to view the state of the eth0;

Of course, you can also use directly in the command IP address, network mask, broadcast address at the same time, activate the network card, to add up the parameters, such as the following example; [Root@localhost ~]# ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0 up

* Example two: in this example, we have to learn to set the network IP address at the same time, learn to set the Physical Address Card (MAC address);

For example, we set the network card eth1 IP address, netmask, broadcast address, physical address and activate it; [root@localhost ~]# ifconfig eth1 192.168.1.252 hw ether 00:11:00:00:11:11 Netmask 255.255.255.0 broadcast 192.168.1.255 up
Or
[Root@localhost ~]# ifconfig eth1 hw ether 00:11:00:00:11:22
[Root@localhost ~]# ifconfig eth1 192.168.1.252 netmask 255.255.255.0 broadcast 192.168.1.255 up

Where HW followed by the network interface type, Ether said that the B-net, but also support ax25, ARCnet, netrom, etc., please see man ifconfig;


How to use Ifconfig to configure virtual network interface;

Sometimes we need to configure the virtual network interface to meet different needs, for example, we use a different IP address to run multiple httpd servers, it is necessary to use a virtual address; This eliminates the same IP address, and if you are opening two HTTPD servers, specify the port number.

Virtual network interface refers to a network interface to specify multiple IP addresses, virtual interface is such eth0:0, Eth0:1, Eth0:2 ... eth1n. Of course, you specify multiple IP addresses for eth1, that is, eth1:0, eth1:1, Eth1:2 ... Analogy

In fact, the use of ifconfig for a network adapter to configure multiple IP addresses, using the previous we said the use of ifconfig, this relatively simple; look at the following example; [Root@localhost ~]# ifconfig eth1:0 192.168.1.251 hw ether 00:11:00:00:11:33 netmask 255.255.255.0 broadcast up
Or
[Root@localhost ~]# ifconfig eth1 hw ether 00:11:00:00:11:33
[Root@localhost ~]# ifconfig eth1 192.168.1.251 netmask 255.255.255.0 broadcast 192.168.1.255 up

Note: when specified, specify a different physical address for each virtual NIC;

In Redhat/fedora or similar systems with Redhat/fedora, you can put the configuration network IP address, broadcast address, mask address, physical address, and activate network interface in one sentence, and write to/etc/rc.d/rc.local. such as the following example; Ifconfig eth1:0 192.168.1.250 hw ether 00:11:00:00:11:44 netmask 255.255.255.0 broadcast up
Ifconfig eth1:1 192.168.1.249 hw ether 00:11:00:00:11:55 netmask 255.255.255.0 broadcast 192.168.1.255 up

Explanation: above is the network interface for ETH1, set up two virtual interfaces, each interface has its own physical address, IP address ...


How to use Ifconfig to activate and terminate the connection of network interface;

Activate and terminate the network interface with the Ifconfig command, followed by the network interface, then add down or up parameters, you can prohibit or activate the corresponding network interface. Of course, you can use special tools Ifup and Ifdown tools. [Root@localhost ~]# ifconfig eth0 down
[Root@localhost ~]# ifconfig eth0 up
[Root@localhost ~]# ifup eth0
[Root@localhost ~]# Ifdown eth0

This is true for activating other types of network interfaces, such as Ppp0,wlan0, but only for network adapters that specify IP.


Note: The IP assigned to DHCP is also activated by the network tools that come with each release, and of course you have to install the DHCP client;

Like Redhat/fedora [root@localhost ~]#/etc/init.d/network start

Slackware release; [Root@localhost ~]#/etc/rc.d/rc.inet1

Redhat/fedora Network Interface configuration file and network interface dedicated configuration tool;

In Redhat/fedora, the configuration files associated with the Ethernet network are located in the/etc/sysconfig/network-scripts directory, such as Ifcfg-eth0, ifcfg-eth1 ...


Redhat/fedora or similar system, the configuration file of the NIC;

For example, in Fedora 5.0, Ifcfg-eth0;

If you use a DHCP server to automatically obtain IP, generally ifcfg-eth0 content is similar to the following; Device=eth0
Onboot=yes
Bootproto=dhcp
Type=ethernet

If you are specifying IP, the general content is similar to the following; Device=eth0 Note: network interface
Onboot=yes Note: Activate at boot time
Bootproto=static Note: The use of static IP address;
ipaddr=192.168.1.238 Note: IP address
netmask=255.255.255.0 Note: Network mask;
gateway=192.168.1.1 Note: gateway;

The following options are also available; HOSTNAME=LINXSIR03 Note: Specifies the host name;
Domain=localdomain Note: Specify Domain name;
HWADDR=00:00:11:22:00:AA Note: Specify the network card hardware address (MAC address), can also be omitted, but here to change the MAC address is generally not effective. Or to change it by means of the Ifconfig method mentioned above;


Redhat/fedora or similar systems, configuration network Tools introduction;

In the early versions of Redhat, there were linuxconf, Redhat-config-network, Netconfig and other tools;

The latest version in Redhat/fedora has System-config-network-tui (text-mode), System-config-network (graphics-mode), Netconfig (text-mode).

These tools will directly modify the Linux system configuration file on the network interface; this is ifconfig;

The Redhat-config-network and system-config-network tools are not only the tools to configure the network card, but also to configure ISDN and common cats, ADSL tools, network hardware additions, host name configuration, DNS client configuration, and so on. is actually a tool group integration;

These tools are simpler and can be invoked by running commands with root privileges, such as: [Root@localhost ~]#/usr/sbin/system-config-network
[Root@localhost ~]# System-config-network

If you set the environment variable for the executable command, you can run it without adding a path, but only if you have to install the Network management tool;

However, it is worth saying that the Netconfig tool is a better tool in the text model, recommended for everyone to use; The reason is that this tool also has a simple graphical interface in text mode, and command mode; the function is strong; [Root@localhost ~]# netconfig-d eth0 Note: Configuring Eth0
[Root@localhost ~]# netconfig-d eth1 Note: Configuring ETH1


Special introduction of Netconfig in Redhat/fedora system;

Netconfig This tool is present in Redhat/fedora or similar systems, and this tool is more powerful. So here's a special introduction. But in the Slackware netconfig is the text mode has a graphics mode, but not like ifconfig with the command to operate the network card interface;

the use of Netconfig is as follows: [Root@localhost ~]# netconfig--help Note: Help;
--bootproto= (Dhcp|bootp|none) Boot protocol to use (
--gateway=string Network Gateway (designated gateways)
--ip=string IP address (specify IP addresses)
--nameserver=string nameserver (Specify DNS client)
--netmask=string netmask (Specify netmask)
--hostname=string hostname (Specify host name)
--domain=string domain name (specify domain name)
-D,--device=string network device (designated network device)
--nodns No DNS lookups (no DNS queries)
--hwaddr=string Ethernet Hardware Address (Specify the physical addresses of the network adapters)
--description=string Description of the device (descriptive text)
Help Options: (helper option)
-?,--Help
--usage Display Brief Usage message

Example One: Set the network card DHCP mode to automatically obtain IP [Root@localhost ~]# netconfig-d eth0--bootproto=dhcp

Instance One: Manually set the IP of the network card, etc. [root@localhost ~]# netconfig-d eth0--ip=192.168.1.33--netmask=255.255.255.0-- gateway=192.168.1.1

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.