Linux command to modify IP information

Source: Internet
Author: User
Tags domain name server
MTU indicates the maximum transmission unit. MTU values are not necessarily the same for different local networks. for Ethernet, MTU sets the Linux command line to modify the IP address, Gateway, and DNS methods.

Method 1:

Ifconfig eth0 192.168.1.18 netmask 255.255.255.0

Note: This method can make changes take effect immediately, and will be restored to the original IP address after restart.

Method 2:

Vi/etc/sysconfig/network-scripts/ifcfg-eth0

Note: This method takes effect after being restarted and is permanent.

If you want to change it immediately and it will take effect permanently, you can only use the two methods at the same time.

The preceding method modifies the IP address through the linux command line.

Nic eth0 IP address changed to 102.160.1

Ifconfig eth0 102.160.1 netmask 255.255.255.0

Change gateway to 102.160.254

Route add default gw 102.160.254

Linux command line dns modification

Echo "nameserver 202.202.202.20">/etc/resolv. conf

Restart network service

Example: change the fixed IP address from the original DHCP
DEVICE = eth0
HWADDR = 00: 0C: 29: F7: EF: BF
ONBOOT = yes
TYPE = Ethernet
NETMASK = 255.255.255.0
IPADDR = 192.168.0.68
GATEWAY = 192.168.0.1
Add red.

Restart Nic:
/Etc/init. d/network restart

Ifconfig eth0 New ip
Then edit/etc/sysconfig/network-scripts/ifcfg-eth0 and modify the ip

[Aeolus @ db1 network-scripts] $ vi ifcfg-eth0

DEVICE = eth0
ONBOOT = yes
BOOTPROTO = static
IPADDR = 219.136.241.211
NETMASK = 255.255.255.255.128
GATEWAY = 219.136.241.254

[Aeolus @ db1 etc] $ vi resolv. conf

Nameserver 202.96.128.68
Nameserver 219.136.241.206

-----------------------
Modify the nic ip address and Gateway in Linux


We recommend that you use the terminal character to modify it.
1. modify the IP address
Vi/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE = eth0
BOOTPROTO = none
BROADCAST = 192.168.1.255
IPADDR = 192.168.1.33
NETMASK = 255.255.255.0
NETWORK = 192.168.1.0
ONBOOT = yes
USERCTL = no
PEERDNS = no
TYPE = Ethernet
~

Vi/etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE = eth1
ONBOOT = yes
BOOTPROTO = none
IPADDR = 192.168.2.34
NETMASK = 255.255.255.0
USERCTL = no
PEERDNS = no
TYPE = Ethernet
NETWORK = 192.168.2.0
BROADCAST = 192.168.2.255
2. modify the Gateway
Vi/etc/sysconfig/network

NETWORKING = yes
HOSTNAME = Aaron
GATEWAY = 192.168.1.1

3. restart the network configuration
/Etc/init. d/network restart



Bytes -----------------------------------------------------------------------------------

Modify configuration file

/Etc/sysconfig/network-scripts/has a configuration file

For example, the File: ifcfg-eth0 represents the configuration file of the actual Ethernet NIC 0

For example, the File: ifcfg-eth0: 1 represents the actual Ethernet NIC 0 configuration file

Domain Name Server Configuration File:/etc/resolv. conf

Modify IP address
Effective immediately:
# Ifconfig eth0 192.168.0.20 netmask 255.255.255.0
Start effective:
Modify/etc/sysconfig/network-scripts/ifcfg-eth0

Modify the default gateway
Effective immediately:
# Route add default gw 192.168.0.254
Start effective:
Modify/etc/sysconfig/network-scripts/ifcfg-eth0

Modify dns
Modify/etc/resolv. conf
The modification takes effect immediately and starts as well.

Modify host name
Effective immediately:
# Hostname fc2
Start effective:
Modify/etc/sysconfig/network

# Realtek semiconduco., Ltd. RTL-8139/8139C/8139C +
DEVICE = eth0 interface name
BOOTPROTO = none static configuration. if this value is "dhcp", it is dynamically obtained. static also indicates static IP address.
BROADCAST = 192.168.10.255 BROADCAST address, automatically calculated by IP address and subnet mask
HWADDR = 00: 13: D3: 27: 9F: 80
IPADDR = 192.168.10.238
IPV6INIT = yes
IPV6_AUTOCONF = yes
NETMASK = 255.255.255.0
NETWORK = 192.168.10.0 indicates the NETWORK, which is automatically calculated using the IP address and subnet mask.
ONBOOT = yes automatically loaded upon startup
GATEWAY = 192.168.10.1
TYPE = Ethernet
PEERDNS = yes
USERCTL = no

Ifdown eth0 disable network
Ifconfig eth0 down disable network

Ifup eth0 enable network
Ifconfig eth0 up enable network

Set dns/etc/resolv. conf

Nameserver 61.144.56.101
Nameserver 202.96.128.166

[Yeger @ yeger ~] $ Cat/etc/resolv. conf
# Generated by NetworkManager
Nameserver 202.96.128.86
Nameserver 202.96.128.166

Other aspects
Service network start // start a network service
Service network stop // stop a network service
Service network restart // restart the network service
Service network status // view the network service status

Ifconfig eth0 192.168.10.222 netmask 255.255.255.0 // temporarily modify the interface IP address (no need to restart the interface)

[Yeger @ yeger ~] $ Sudo ifconfig wlan0 192.168.21.199 netmask 255.255.255.0
[Yeger @ yeger ~] $ Ifconfig wlan0
Wlan0 Link encap: Ethernet HWaddr 00: 02: 72: 77: BB: D1
Inet addr: 192.168.21.199 Bcast: 192.168.21.255 Mask: 255.255.255.0
Inet6 addr: fe80: 202: 72ff: fe77: bbd1/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 3246 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 1947 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 fig: 1000
RX bytes: 4514869 (4.3 MiB) TX bytes: 177732 (173.5 KiB)
Wlan0 indicates the first wireless Ethernet card
Link encap indicates the name of the network adapter in the OSI Physical Layer.
HWaddr indicates the MAC Address of the NIC (Hardware Address)
Inet addr indicates the IP address of the network adapter in the TCP/IP network.
Bcast indicates the broadcast Address (Broad Address)
Mask indicates the Subnet Mask (Subnet Mask)
MTU indicates the maximum transmission unit. MTU values are not necessarily the same for different local networks. for Ethernet, the default MTU value is 1500 bytes.
Metric indicates the Metric value, which is usually used to calculate the route cost.
RX indicates the received data packet
TX indicates the sent data packet
Collisions indicates the number of packet conflicts
Txqueuelen indicates the Transfer Queue length.
Interrupt indicates the IRQ interrupt number of the Eni.
Base address indicates the I/O address

Configure the virtual network interface IP address: the network interface must have multiple IP addresses.

Command format: ifconfig Nic name: Virtual nic id ip address netmask subnet mask

[Yeger @ yeger ~] $ Sudo ifconfig wlan0: 1 192.168.21.188 netmask 255.255.255.0

Change the Nic MAC address

Ifconfig Nic name hw ether MAC address

[Yeger @ yeger ~] $ Ifconfig wlan0 hw ether 00: 11: 22: 33: 44: 55


SIOCSIFHWADDR: Operation not allowed
[Yeger @ yeger ~] $ Sudo ifconfig wlan0 hw ether 00: 11: 22: 33: 44: 55
SIOCSIFHWADDR: the device or resource is busy.
[Yeger @ yeger ~] $ Ifconfig wlan0 down
SIOCSIFFLAGS: insufficient permissions
[Yeger @ yeger ~] $ Sudo ifconfig wlan0 down
[Yeger @ yeger ~] $ Sudo ifconfig wlan0 hw ether 00: 11: 22: 33: 44: 55
Changed

[Yeger @ yeger ~] $ Netstat-ant view port information a all n numbers Display t tcp protocol u udp protocol
Active Internet connections (servers and established have established a connection)
Proto Recv-Q Send-Q Local Address Foreign Address State
Protocol local address remote address connection status
Type
Tcp 0 0 0.0.0.0: 57798 0.0.0.0: * LISTEN listen indicates the listening status
Tcp 0 0 0.0.0.0: 111 0.0.0.0: * LISTEN
Tcp 0 0 192.168.122.1: 53 0.0.0.0: * LISTEN
Tcp 0 0 0.0.0.0: 22 0.0.0.0: * LISTEN
Tcp 0 0 127.0.0.1: 631 0.0.0.0: * LISTEN
Tcp 0 0 127.0.0.1: 25 0.0.0.0: * LISTEN
Tcp 0 0: 111: * LISTEN
Tcp 0 0: 22: * LISTEN
Tcp 0 0: 1: 631: * LISTEN

[Yeger @ yeger ~] $ Netstat-r View route table
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.21.0*255.255.255.0 U 0 0 0 wlan0
192.168.122.0*255.255.255.0 U 0 0 0 virbr0
Default 192.168.21.1 0.0.0.0 UG 0 0 0 wlan0

[Yeger @ yeger ~] $ Netstat-I view the network interface status
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR Flg
Eth0 1500 0 0 0 0 0 0 0 0 BMU
Lo 16436 0 230 0 0 230 0 0 0 LRU
Virbr0 1500 0 0 0 0 29 0 0 0 BMRU
Wlan0 1500 0 10546 0 0 7060 0 0 0 BMRU
Wmaster0 0 0 0 0 0 0 0 0 0 RU
[Yeger @ yeger ~] $

MTU field: indicates the maximum transmission unit, that is, the maximum number of packets transmitted by network interfaces.
Met field: indicates the metric value. The smaller the value, the higher the priority.
RX-OK/TX-OK: number of packets received and sent, respectively.
RX-ERR/TX-ERR: number of error packets received and sent.
RX-DRP/TX-DRP: indicates the number of dropped.
RX-OVR/TX-OVR: indicates the number of dropped packets.

[Yeger @ yeger ~] $ Nslookup test domain name resolution
Server: 202.96.128.86
Address: 202.96.128.86 #53

Non-authoritative answer:
Canonical name =
Name:
Address: 119.75.218.45
Name:
Address: 119.75.218.45

The IP address of Baidu is 119.75.218.45.

Related Article

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.