Centos gateway, IP, DNS, and other configurations (written to the configuration file, valid for a long time)

Source: Internet
Author: User

Recently, I finally had a hard time worrying about the existence of centos5.6 on my PC for three months. It was a long journey, and the Linux road started.

Boot With grub, c5.6 boot, in the network that, each loading is very slow. You cannot access the Internet after starting the instance. You can ping the gateway and unreachable on the terminal.

So I slowly suspected that the network information configured in the lab was correct.

1. Detection

Terminal input # ifconfig, found that the configuration information is quite messy, IP is not set, gateway, bootmask is not set.

2. Configuration

(1) Use commands to directly configure the configuration. The advantages are convenient and fast, and the disadvantages are that the configuration cannot be saved. You must reconfigure the configuration every time you restart the instance.

# Up eth0 <! -- Activate the NIC -->

# Down eth0 <! -- Disable Nic -->

# Ifconfig eth0 192.168.1.135 <! -- Configure IP -->

# Route add default GW 192.168.1.1 <! -- Configure the default gateway -->

# Ifconfig netmask 255.255.255.0 up <! -- Set the subnet mask (effective immediately) -->

For more configuration information, refer to: Baidu Library Linux configuration command

(2) rewrite the configuration file. The advantage is that it is valid once and for a long time. Disadvantage? It is not suitable for beginners.

# Vim/etc/sysconfig/Network

# I <! -- Vim insert a shortcut command -->/* append :*/

Networking = Yes
Networking_ipv6 = Yes
Hostname = localhost. localdomain
Gateway = 192.168.1.1

[ESC]

# ZZ (uppercase, VIM command, save and Exit)
# Vim/etc/sysconfig/network-scripts/ifcfg-eth0

Append->

Device = eth0
Hwaddr = 6C: 62: 6d: EB: C9: CD
Ipaddr = 192.168.1.156
Netmask = 255.255.255.0
Gateway = 192.168.1.1
Onboot = Yes
Type = Ethernet
Bootproto = static
# ZZ exits vim, Ping 192.168.1.1 is normal, Ping 8.8.8.8 is normal, and Ping Baidu.com is normal

Now that the configuration is complete, you can access the Internet normally.

One point is that during the configuration process, I write ipaddr as ipadder, which leads to the error of can't specify device or ipaddr!

Careful, bloody lessons, and the Post Method Used in Ajax last night, while the PHP script received it with $ _ get. I am really a talented person!

 

  

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.