Ifconfig, DNS, and route configurations in Linux

Source: Internet
Author: User
Tags domain name server nameserver nslookup command

 

Original article: http://www.cnitblog.com/201/archive/2009/08/20/60887.html

It is very convenient to be familiar with ifconfig.

Ifconfig eth0 new ip

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

1. Modify the IP address

[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

2. Modify the Gateway

Vi/etc/sysconfig/network

NETWORKING = yes

HOSTNAME = Aaron

GATEWAY = 192.168.1.1

3. Modify DNS

[Aeolus @ db1 etc] $ vi resolv. conf

Nameserver 202.96.128.68

Nameserver 219.136.241.206

4. Restart Network Configuration

/Etc/init. d/network restart

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
I. Linux basic network configuration command
1. ifconfig view network interface information. Common users use the full path of ifconfig:/sbin/ifconfig

Ifconfig Network Interface Name: displays the details of the specified interface.

Ifconfig-a to view information about all network interfaces.

2. route table display

Route | grep default: displays the default gateway of the host.

3. ping-c 4 192.168.1.10 to send a specified number of packets for network connection testing.

4. traceroute 192.168.1.10 test the network connection path with other hosts.

5. the hostname displays the current host name.

2. Use commands to set the network

1. dhclient applies for new network settings from the DHCP server.

2. ifconfig network interface ip address netmask subnet mask: configure the ip address. The Network Interface attribute set by the ifconfig command is valid only when the current system is running, after the system restarts, the network interface properties will be reconfigured according to the content of the network interface configuration file.

3. route del default gw default gateway address: Delete the default gateway route record.

Route add default gw default gateway address: add default gateway.

4. hostname Linserver: Set the host name to take effect immediately. After the host is restarted, the original host name will be restored.

5. Use the server command in the interactive mode of the nslookup command to display the DNS server address used in linux.

6. netconfig: configure the network on the Character interface.

Service network restart: restart the network service.

Ifdown Network Interface

Ifup Network Interface: restart Network Interface

7. Modify the mac address:

Ifconfig eth0 down: Disable Nic first

Ifconfig eth0 hw ether 1234567890ab

Always keep like this:

Add these three sentences to/etc/rc. d/rc. local (you can also add the following three lines to/etc/init. d/network)

Ifconfig eth0 down
Ifconfig eth0 hw ether 1234567890ab
Ifconfig eht0 up

3. modify the configuration file for Network Configuration

1. network Interface Configuration File:/etc/sysconfig/network-scripts/ifcfg-eth0

/Etc/sysconfig/network-scripts/ifcfg-lo

The static IP address settings in the ifcfg-eth0 configuration file are as follows:

Device = eth0 set the network interface Name

Onboot = Yes sets the network interface to be activated when the system starts.

Bootproto = static is configured as a static address

Ipaddr = 192.168.1.10

Netmask = 255.255.255.0

Gateway = 192.168.1.1 default gateway for network interfaces

Obtain the network configuration using DHCP:

Device = eth0

Onboot = Yes

Bootproto = DHCP

2. Host Name configuration file/etc/sysconfig/Network

Networking = Yes

Hostname = linserver is the host name.

3. Local host name resolution file/etc/hosts

4. Domain Name Server configuration file/etc/resolv. conf

Search lingdian.com sets the default domain name for the host.

Nameserver 192.168.152.2 sets the IP address of the DNS server. The file can contain a maximum of three "nameserver" configuration records, each of which records a row. The system will give priority to the top "nameserver" configuration records.

Linux basic network configuration command

1. View IP Address: ifconfig

2. IP Address Configuration method:

A. This method takes effect immediately, but will not be saved after restart. (Other Methods except this method can be saved)

Ifconfig eth0 1.1.1.1 netmask 255.0.0.0 up

Ifconfig eth01 1.1.1.3 up how to set multiple IP addresses of one NIC (used when setting a VM)

Enable NIC: ifconfig eth0 up

Disable NIC: ifconfig eth0 down

Dynamic IP retrieval: ifconfig etho-dynamic

Dhclient

Modify the MAC value: first disable the NIC: ifconfig eth0 down

Then modify the MAC value: ifconfig eth0 HW ether 112233445566.

Reactivate the NIC: ifconfig eth0 up

B. netconfig or setup, but only eth0 Nic can be set

C. Neat: Open the graph window and set it.

D. Configuration File Settings:

Vi etcsysconfignetwork-scriptsifcfg-eth0

Note: If the restart of the NIC Service network restart fails after configuration, use the fourth method to check whether the Bootup in the configuration file is None. If it is DHCP, an error occurs.

3. Configure the Gateway:

View Gateway: route

Add default route:

Route add-net 0.0.0.0 netmask 0.0.0.0 gw 192.168.0.1

Delete default route:

Route del-net 0.0.0.0 netmask 0.0.0.0 gw 192.168.0.1

4. Configure dns:

Echo nameserver 192.168.0.1etcresolv.conf

Linux route Configuration:

1. First enable the routing function

Echo 1 procsysnetipv4ip_forward (1 indicates enabling the routing function, and 0 indicates disabling the routing function)

(In this experiment, you only need to enable the routing function)

2. Other route settings:

A. Add route information:

Route add-net 10.0.0.1 netmask 255.0.0.0 gw 192.168.0.1

Or route add-net 10.0.0.1 netmask route 0.0.0 dev eth0 (go out through the first Nic of the local machine)

Delete route entries: you only need to change Add to Del.

B. Configure the route using Zebra (the configuration is the same as that of Cisco ):

1) set the logon password:

VI etczebrazebra. conf

Password ABC # Set the connection password

Enable Password 123 # Set a privileged Password

2) enable the Service

Service zebra start

3) Create the route protocol file to be configured

For example, use the RIP Protocol: Touch etczebraripd. conf.

4) Enable the RIP Protocol: Service ripd start

5) Enter Zebra:

Method 1. Telnet 127.0.0.1 2601 # Remember that the port is 2601

If no password is set, connections are not allowed by default. This is suitable for remote logon.

Method 2: vtysh # access without a password. If a password is displayed, it is only applicable to local logon.

6) configure the route: the route is the same as that in the Cisco router.

7) Quit quit (save it before exiting)

 

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.