Linux ifconfig usage and configuration file

Source: Internet
Author: User

Nic naming rules in Linux: eth0 and eth1. The first Ethernet Card and the second card. Lo is the loopback interface, its IP address is fixed to 127.0.0.1, And the mask is 8 bits. It represents your machine.

1. ifconfig is used to view the NIC information.

Ifconfig [interface]

Interface is optional. If this option is not added, information about all NICs in the system is displayed. If this option is added, the specified Nic information is displayed.

For example, ifconfig eth0

eth0 Link encap:Ethernet
HWaddr 00:0C:29:F3:3B:F2
inet addr:192.168.0.10 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:78 errors:0 dropped:0 overruns:0 frame:0
TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:11679 (11.4 Kb)
TX bytes:14077 (13.7 Kb)
Interrupt:10 Base address:0x1080

We can see that

Line 1: Connection Type: Ethernet (Ethernet) hwaddr (hardware MAC address)

Line 2: IP address, subnet, and mask of the NIC

Row 3: Up (indicating that the network card is enabled) running (indicating that the network card is connected) multicast (supporting Multicast) MTU: 1500 (maximum transmission unit): 1500 bytes

4. Five Elements: Statistics on received and sent data packets

Row 7: number of bytes of received and sent data.

2. Configure the NIC in ifconfig

Configure the IP address of the NIC

Ifconfig eth0 192.168.0.1 netmask 255.255.255.0

Configure the IP address and 24-bit mask of 192.168.0.1 on eth0. What if I want to configure another IP address 192.168.1.1/24 on eth0? Use the following command

Ifconfig eth0: 0 192.168.1.1 netmask 255.255.255.0

Then run the ifconifg command to view the information of the two NICs: eth0 and eth0: 0. If you want to add more IP addresses, enter the names of the network adapters: eth0: 1, eth0: 2. OK!

Configure the hardware address of the NIC

Ifconfig eth0 HW ether XX: xx

You can change the hardware address of the NIC, and then you can cheat the IP address in the LAN.

Disable Nic

Ifconfig eth0 down

Enable the NIC

Ifconfig eth0 up

The ifconfig command has powerful functions. You can also set the MTU and hybrid mode of the NIC. I will not discuss it one by one. I can study it myself in time.

Note: The NIC information configured using the ifconfig command does not exist after the NIC is restarted. To save the above configuration information to your computer forever, you need to modify the NIC configuration file.

The wind finally gets blown away by the rain ...... Customized Linux
Nic configuration (1) Nic configuration file (
1
)
/Etc/sysconfig/network-scripts/ifcfg-interface-name configuration file
Ifcfg-interface-name
Contains most of the details required to initialize the interface. Where
Interface-name
The name is generally named
Eth0
,
Eth1
,
Ppp0
And so on.
ETH
Indicates that (
Eth0
) Type Nic,
0
Indicates the first Nic,
1
Indicates the second Nic, while
Ppp0
Indicates the first
Point-to-poirt Protocol
Network interface. In
Ifcfg
The items defined in the file depend on the interface type. The following values are more common:
Device = Name
, Where,
Name
Is the name of a physical device.
Ipaddr = ADDR
, Where,
ADDR
Yes
IP
Address.
Netmask = mask
, Where,
Mask
Is the network mask value.
Network = ADDR
, Where
ADDR
Is the network address.
Broadcast = ADDR
, Where,
ADDR
Is the broadcast address.
Gateway = ADDR
, Where
ADDR
Is the gateway address.
Onboot = answer
, Where,
Answer
Yes
Yes
(Activate the device during boot) or
No
(Device not activated during boot)
Userctl = answer
, Where,
Answer
Yes
Yes
(Non
Root
The user can control the device) or
No
Bootproto = proto
, Where,
PROTO
Take one of the following values:
None
, No protocol is used for guidance;
Static
Static allocation address;
BOOTP
, Use
BOOTP
Protocol, or
DHCP
, Use
DHCP
Protocol. (
2
) According to the meaning of the above parameters, Set
Linpcl.lintec.edu.cn
The machine setting file is as follows: [root @ linpcl root] # Cat/etc/sysconfig/networking/devices/ifcfg-rth0DEVICE = eth0onboot = yesbootproto = staticipaddr = 192.168.0.2netmask = 255.255.255.0gateway = 192.168.0.1 (3)
Save the file and use
/Etc/init. d/network restart
Command to restart the network device. The latest value takes effect. [Root @ linpcl root] #/etc/rc. d/init. d/network restart is shutting down the interface
Eth0
:

[
OK
] Disable the loopback interface:

[
OK
] SET network parameters:

[
OK
] The loopback interface is displayed:

[
OK
] Pop-up Interface
Eth0
:

[
OK
] (
4
) Use
Ifconfig
Command to view the network device status. [Root @ linpcl root] # ifconfigeth0
Link encap: Ethernet hwassr 52
:
54
:
AB
:
28
:
EE
:
37
Linet ADDR
:
192.168.0.2 bcast
:
192.168.0.255 mask
:
255.255.255.0

(Some parameter files are automatically displayed, Which is omitted here )...

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.