Network configuration file Location:/etc/sysconfig/network
Network Interface configuration file:
/etc/sysconfig/network-scripts/ifefg-interface_name
Content settings for configuration files: Content in profiles is strictly case- sensitive
Device=eth0 (associated device name, which must be consistent with the second half of the file name)
BOOTPROTO={STATIC|NONE|DHCP|BOOTP} bootstrap protocol, static address, DHCP represents dynamic acquisition
IPADDR=IP address setting IP address
netmask= Subnet mask configuration subnet Mask
gateway= Default gateway setting default gateway
Onboot={yes|no} sets whether the network interface is activated automatically when booting ;
Hwaddr=mac address to be consistent with the address in the hardware ,
Userctl={yes|no} whether the interface is allowed to be controlled by a normal user (by default it can be saved)
Peerdns={yes|no} whether to accept the DNS address specified by the DHCP server when Bootproto is DHCP (the default also saves)
Modifying the configuration file does not take effect immediately, but it takes effect after restarting the network service or host and is permanently valid.
[Email protected] etc]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0
Device=eth0
hwaddr=00:0c:29:36:4c:72
Type=ethernet
Uuid=e7e817cb-c464-48c7-9cea-417de960df38
Onboot=yes
Nm_controlled=yes
Bootproto=static
ipaddr=10.109.134.236
netmask=255.255.252.0
gateway=10.109.132.1
dns1=10.109.131.131
dns2=10.109.131.132
Routing profile:/etc/sysconfig/network-scripts/route-ethx routing profile x is the network interface number
Add format one:
DEST via Nexthop # DEST is the target subnet segment and needs to be written with a mask or destination name Nexthop next-hop address
Usage: vim /etc/sysconfig/network-scripts/route-eth1
10.109.134.0/22 via 10.109.132.1 first static route
10.109.135.0/22 via 10.109.135.1 second static route
* Static routes are usually added using the first format.
Add format two:
address0= Destination Address
netmask0= Subnet Mask
gateway0= Next Hop Address
Usage:vim /etc/sysconfig/network-scripts/route-eth1
address0=10.109.134.0
netmask0=255.255.252.0
gateway0=10.109.132.1
Route Introduction to Commands:
View or add routing information.
1 . Command format:
Route add-net|-host IP Subnet address GW Next hop gateway address
Route add default GW next-Hop gateway address Add a defaults route simply enter
2 . Command function:
View or add routing information , which takes effect immediately after the change, but resets the network card service or the machine, the setup fails.
3 . Command parameters:
Route
-N Displays information about each host or port in a digital manner
Add: Adding
-host: Host Routing
-net: Network Routing
Del: Delete
Route Del-net 10.0.0.0/8 or if there's only one 10.0.0.0
Remove route del-net 10.0.0.0 without specifying a mask
Remove default route route del default
4 . Command instance:
1. View routing Information
[Email protected] etc]# route
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
10.109.132.0 * 255.255.252.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
Default 10.109.132.1 0.0.0.0 UG 0 0 0 eth0
[Email protected] etc]#
[Email protected] etc]# route-n
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
10.109.132.0 0.0.0.0 255.255.252.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
0.0.0.0 10.109.132.1 0.0.0.0 UG 0 0 0 eth0
ifconfig Command Introduction:
View or configure network card IP information
1 . Command format:
Ifconfig ethx Ip/mask [Up|down]
2 . Command function:
View or configure network IP related information, effective immediately after modification, but re-activate the network card service or machine, setup failure.
3 . Command parameters:
-A: Displays configuration information for all network interfaces
4 . Command instance:
1. Check the interface information of the first NIC;
ifconfig eth0
[[email protected] rules.d]# ifconfig eth0 View IP information such as network interface 0
Eth0 Link encap:ethernet HWaddr 00:0c:29:36:4c:72
inet addr:10.109.134.236 bcast:10.109.135.255 mask:255.255.252.0
Inet6 ADDR:FE80::20C:29FF:FE36:4C72/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:11817451 errors:346 dropped:362 overruns:0 frame:0
TX packets:53355 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:972504422 (927.4 MiB) TX bytes:8371995 (7.9 MiB)
Interrupt:19 Base address:0x2000
2, view all the information of the interface;
Ifconfig-a
[[email protected] rules.d]# ifconfig-a View information for all interfaces
Eth0 Link encap:ethernet HWaddr 00:0c:29:36:4c:72
inet addr:10.109.134.236 bcast:10.109.135.255 mask:255.255.252.0
Inet6 ADDR:FE80::20C:29FF:FE36:4C72/64 Scope:link
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:11820584 errors:346 dropped:362 overruns:0 frame:0
TX packets:53378 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:972766851 (927.7 MiB) TX bytes:8375233 (7.9 MiB)
Interrupt:19 Base address:0x2000
Lo Link encap:local Loopback Local loopback interface
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:619 errors:0 dropped:0 overruns:0 frame:0
TX packets:619 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:68186 (66.5 KiB) TX bytes:68186 (66.5 KiB)
3, set the network card address (the network card set address, restart the machine or network service after failure)
Ifconfig eth0 10.109.134.236/22
[[email protected] rules.d]# ifconfig eth0 10.109.134.236/22 Set IP address,/22 for specified subnet mask
[email protected] rules.d]# ifconfig eth0 up|down Enable or disable the NIC
This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1871836
Linux command: ifconfig route