The summary of network configuration under Linux

Source: Internet
Author: User
Tags command line reset win32 nameserver linux

For Linux master seemingly simple network configuration problem, perhaps to say why it is not easy, so there are still too many beginners wandering outside the door is not strange,

Here, the old boy teacher spent some time summarizing this document summary, also not perfect, welcome everyone to add, Exchange. Thank you! 20120827 Supplements:

http://oldboy.blog.51cto.com/2561410/974194 Simple Route Command Summary

Directory:

1) Configure modify host name hostname

2 Network Card configuration file Description:

3) Configure modify IP address

4) Configuration Modification Gateway Gateways

5 Configuration Modification DNS

6 View IP, gateway or routing, DNS configuration

a.[view IP Configuration method]

b.[view gateways and routing methods]

c.[view DNS Configuration method]

7 if Win32 and Linux servers are unable to connect to the network, describe the method of troubleshooting separately?

##########################

### #1) configuration Modify host Name:

##########################

Temporary method:

Hostname Oldboy

Exit the current shell and log back on to take effect. This method can only be temporarily modified to take effect, and will fail after the system is reset.

Tip: Many people use hostname hostname to modify, in fact this is only temporary, reboot will revert to the configuration before the host name.

Permanent method:

Law I:

Step 1:

Vi/etc/sysconfig/network

Change the inside hostname=xx to Hostname=oldboy and save it.

Tip: After the change here, the implementation of/etc/init.d/network restart or source/etc/sysconfig/network and other practices are not effective

If you want to modify this file single, you may need to reboot the server.

Digression: Here should be a direct effective method of the system with the current and permanently effective method, is the load under the hostname call configuration file under the command to execute,

Leave this question to everyone!

Step 2:

Then continue to modify through the command line: hostname Oldboy, after the completion of the withdrawal of the landing is effective

Hint: This will guarantee the temporary effect, and the system will be in effect again.

Law II:

An additional modification that will take effect immediately and permanently: Perform setup-network configuration--Edit DNS configuration-->

DNS Configuration

x x

x Hostname oldboy_______ x ===========> Modify here

X Primary DNS 202.106.0.20___ x

X secondary DNS 211.147.6.3____ x

X Tertiary DNS _______________ x

x Search _______________ X

Tip: Here after the save will be effective in time, restart also effective, from this can be seen, the system or has a direct temporary permanent all effective methods.

Special Note: Use the above method may cause the 127.0.0.1 corresponding hostname in/etc/hosts not modified, at this time, should revise manually: for example:

[Root@oldboy ~]# cat/etc/hosts

# do don't remove the following line, or various programs

# that require network functionality would fail.

127.0.0.1 Oldboy localhost.localdomain localhost ===========> modify the Oldboy here

:: 1 localhost6.localdomain6 Localhost6

10.0.0.190 www.etiantian.org

Hint: If/etc/hosts does not change, later will encounter some problems, such as SendMail startup slow, LDAP Service resolution slow, sudo user slow and so on are the host name and/etc/hosts resolution does not correspond to cause.

Development: Scripting for resetting the system settings host name:

[Root@oldboy ~]# grep-i Hostname/etc/rc.d/rc.sysinit

Hostname= '/bin/hostname '

If [-Z "$HOSTNAME"-o "$HOSTNAME" = "(none)"]; Then

Hostname=localhost

# Set the hostname.

Update_boot_stage Rchostname

Action $ "Setting hostname ${hostname}:" Hostname ${hostname} ===========> This is where the machine name is modified after the system has been reset and executed after rc.sysinit.

# Use the ' network ' to set the hostname of the client. This

If ["$HOSTNAME" = "localhost"-o "$HOSTNAME" = "Localhost.localdomain"]; Then

Hostname ${hostname}

Mount-t NFS $CLIENTSTATE/$HOSTNAME $STATE _mount-o Rw,nolock

# Reset the hostname.

Action $ "resetting hostname ${hostname}:" Hostname ${hostname}

[Root@oldboy ~]# grep-i hostname/etc/rc.d/init.d/network ===========> There is no information associated with the hostname.

################################

### #2) network card configuration file Description:

################################

[Root@oldboy ~]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0 = = "This is the default profile for Eth0 network adapter device

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

Device=eth0 ================ "Here is the network card name the first card is eth0, the second is eth1 ...

bootproto=static============ "Static is a fixed IP address, non-dynamic DHCP access

broadcast=10.0.0.255 ======= "Here is the broadcast address, generally the last address of the network address.

hwaddr=00:0c:29:0e:5f:63 = = "Here MAC address, different machines can not repeat, especially in the engraving virtual machine or copy network card configuration should be noted."

ipaddr=10.0.0.161 ========== "Here is the IP address

netmask=255.255.255.0======= Subnet Mask/24

network=10.0.0.0 ========= "Network segment setting

Onboot=yes ================= "power-on Nic self-starter

gateway=10.0.0.254========== the configuration of the gateway, you can also command lines to add deletions via route.

type=ethernet=============== "type

Tip: The first card is Ifcfg-eth0, the second is ifcfg-eth1 ...

################################

### #3) configuration Modify IP address:

################################

To configure network configurations such as server IP and DNS:

1 setup-network configuration, and then modify.

2 directly edit or handwriting the above configuration file.

/etc/sysconfig/network-scripts/ifcfg-eth0 =============== "network card configuration

/etc/resolv.conf=============== Configuration of DNS Client

Tip: The above two methods generally need to be restarted or reloaded/etc/init.d/network restart or/etc/init.d/network reload to take effect.

##########################

### #4) Configuration modification Gateway GW:

##########################

Law One: Modify/etc/sysconfig/network

[Root@oldboy network-scripts]# Cat/etc/sysconfig/network

Networking=yes

Networking_ipv6=no

Hostname=oldboy

gateway=10.0.0.254 = "This is the configuration of the gateway

prompt;/etc/init.d/network reload is required to take effect.

Law II: Modify/etc/sysconfig/network-scripts/ifcfg-eth0

[Root@oldboy network-scripts]# Cat Ifcfg-eth0

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]

Device=eth0

Bootproto=static

broadcast=10.0.0.255

hwaddr=00:0c:29:0e:5f:63

ipaddr=10.0.0.161

netmask=255.255.255.0

network=10.0.0.0

Onboot=yes

gateway=10.0.0.254==== "This is to increase the configuration of the gateway, the default does not

Hint: The/etc/init.d/network restart or reload is required to take effect.

Special attention:

1) The gateway configuration in/etc/sysconfig/network-scripts/ifcfg-eth0 takes precedence over/etc/init.d/network

2 Note that the configuration of the case, gateway=10.0.0.254 such lowercase format is not correct.

Method Three: Modify the default gateway by command:

[Root@oldboy network-scripts]# route del default GW 10.0.0.254 = =) First deleted

[Root@oldboy network-scripts]# Route-n = = "View command

Kernel IP Routing Table

Destination Gateway genmask Flags Metric Ref use Iface

10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

[Root@oldboy network-scripts]# route add default GW 10.0.0.254 = =

[Root@oldboy network-scripts]# Route-n

Kernel IP Routing Table

Destination Gateway genmask Flags Metric Ref use Iface

10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

0.0.0.0 10.0.0.254 0.0.0.0 UG 0 0 0 eth0

Note: This modification is a temporary modification, it will fail after reloading or starting the NIC, and the solution is to configure it as much as possible in the configuration file.

Really need to put route add default GW 10.0.0.254 into rc.local from the boot file or/etc/init.d/network network card

Restart/reload section Script configuration in the implementation of the boot or restart network card also effective, which is a bit too complicated, let's not do it, okay?

##########################

### #5) Modify host DNS configuration

##########################

Method One: setup--Network configuration graphics operation

Law II: modify/etc/resolv.conf = = Here The path of the host DNS configuration file

[Root@oldboy network-scripts]# cat/etc/resolv.conf

NameServer 202.106.0.20

NameServer 8.8.8.8

NameServer 211.147.6.3

Tip: Each configuration line this resolv.conf is directly effective after modification, note, not nameservers,

In addition, this configuration file is also knowledgeable, the students can man resolv.conf view.

##########################

# # #6) View IP, gateway, or routing, DNS configuration:

##########################

[A. View IP configuration methods]

[Root@oldboy ~]# ifconfig = = Direct command name indicates all network card IP

Eth0 Link encap:ethernet hwaddr 00:0c:29:1d:28:d5

inet addr:10.0.0.190 bcast:10.0.0.255 mask:255.255.255.0

Inet6 ADDR:FE80::20C:29FF:FE1D:28D5/64 Scope:link

Up broadcast RUNNING multicast mtu:1500 metric:1

RX packets:4154 errors:0 dropped:0 overruns:0 frame:0

TX packets:3107 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:367589 (358.9 KiB) TX bytes:481210 (469.9 KiB)

interrupt:185 Base address:0x1400

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:36 errors:0 dropped:0 overruns:0 frame:0

TX packets:36 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:3744 (3.6 KiB) TX bytes:3744 (3.6 KiB)

[Root@oldboy ~]# ifconfig eth0 = = To display the specified network card IP

Eth0 Link encap:ethernet hwaddr 00:0c:29:1d:28:d5

inet addr:10.0.0.190 bcast:10.0.0.255 mask:255.255.255.0

Inet6 ADDR:FE80::20C:29FF:FE1D:28D5/64 Scope:link

Up broadcast RUNNING multicast mtu:1500 metric:1

RX packets:4170 errors:0 dropped:0 overruns:0 frame:0

TX packets:3130 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:368687 (360.0 KiB) TX bytes:484496 (473.1 KiB)

interrupt:185 Base address:0x1400

[B. View gateways and Routing methods]

[Root@oldboy network-scripts]# Route-n

Kernel IP Routing Table

Destination Gateway genmask Flags Metric Ref use Iface

10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

0.0.0.0 10.0.0.254 0.0.0.0 UG 0 0 0 eth0

[Root@oldboy ~]# Netstat-rn = = "This method can not remember, remember route-n can."

Kernel IP Routing Table

Destination Gateway genmask Flags MSS Window Irtt iface

10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

View the commands for Linux command help man or info or command--help:

Example: View route usage

Man route and Info route or Route--help

Route powerful, students to master, the above is only a simple usage.

[C. View DNS configuration methods]

[Root@oldboy ~]# cat/etc/resolv.conf = = "This is a common method of inspection.

NameServer 202.106.0.20

[Root@oldboy ~]# Ping g.cn = = "This is a common check method, return the IP address of the explanation pass."

PING g.cn (74.125.71.160) bytes of data.

Bytes from hx-in-f160.1e100.net (74.125.71.160): icmp_seq=1 ttl=49 time=51.7 ms

[Root@oldboy ~]# Host www.etiantian.org = = "This is a common method of checking, return IP address to explain DNS pass.

Www.etiantian.org has address 211.100.98.99

---g.cn ping statistics---

1 packets transmitted, 1 received, 0% packet loss, time 0ms

RTT Min/avg/max/mdev = 51.710/51.710/51.710/0.000 ms

[Root@oldboy ~]# Dig www.etiantian.org

; <<>> DiG 9.3.6-p1-redhat-9.3.6-4.p1.el5 <<>> www.etiantian.org

;; Global Options:printcmd

;; Got Answer:

;; ->>header<<-opcode:query, Status:noerror, id:45736

;; Flags:qr Rd RA; Query:1, Answer:1, authority:0, additional:0

;; Question section:

; www.etiantian.org. In A

;; ANSWER section:

www.etiantian.org in A 211.100.98.99

;; Query time:90 msec

;; server:202.106.0.20#53 (202.106.0.20)

;; When:mon Feb 20 11:50:57 2012

;; MSG SIZE rcvd:51

[Root@oldboy ~]# nslookup

> www.etiantian.org

server:202.106.0.20

address:202.106.0.20#53

Non-authoritative Answer:

Name:www.etiantian.org

address:211.100.98.99

7 if Win32 and Linux servers are unable to connect to the network, describe the method of troubleshooting separately?

This problem is left to everyone. Everyone can comment or talk to me alone.

Hint: The basic examination thought:

A. Physical links are unobstructed

B. Native IP, routing, and DNS settings are up to standard.

C. Test the patency of the gateway or router.

D. Test the normal situation of ping public network IP (to remember several external IP at ordinary times)

E. Test the patency of DNS, you can ping etiantian.org to see if the corresponding IP.

Based on the results of each level to troubleshoot, if the system administrator, the above issues are checked, you can also on the gateway routing server up and down testing.

Step through the investigation.

The old boy teacher looks forward to more ideas and ways to troubleshoot.

This article is from the "Old boy Linux Training" blog, please be sure to keep this source http://oldboy.blog.51cto.com/2561410/784625

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.