Set IP, Gateway, and DNS in Centos environment

Source: Internet
Author: User
Tags nameserver
Below are some of my personal study notes for my personal use only. Set the host name of the system: hostnamelinux. test (you can directly use hostname to display the host name of the current system) enable eth0: ifconfigeth0up (down)

Below are some of my personal study notes for my personal use only.

Set the host name of the system: hostname linux. test (you can directly use hostname to display the host name of the current system)
Enable eth0: ifconfig eth0 up (down) or ifup eht0
View network configuration: ifconfig-
Set IP address: ifconfig eth0 192.168.1.45 netmask 255.255.255.0 up (up indicates immediate activation)

Restart network settings: service network restart
View the current route information: route
Delete a route: route del-net 169.254.0.0 netmask route 255.0.0
Add route: route add-net 169.254.0.0 netmask route 0.0 dev eth0
Set the default gateway: route add default gw 192.168.1.1
Set DNS: echo "nameserver 211.98.1.28">/etc/resolv. conf

Here is the network abstract:

In Linux, whether you are a server or just a common user, surfing the internet is certainly one of the most important and indispensable factors, so it involves network configuration and use such as its ip gateway dns. However, there are two methods to set the linux network:

First, use the command to modify the changes (the changes take effect immediately and the restart fails)
# Ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up
Note:
Eth0 is the first Nic, and the others are eth1, eth *
192.168.0.1 is the IP address configured for the first Nic
Netmask 255.255.255.255.0 is configured with a subnet mask.
Up indicates immediate activation.

Gateway
# Route add default gw 192.168.30.1 eth0

Dns:
# Vi etc/resolv. conf
Nameserver 202.131.80.1
Nameserver 202.131.80.5

If the restart takes effect, write these to the startup script rc. local.

Type 2: modify the configuration document (you need to restart the network configuration to always take effect)

1. modify the IP address

/Etc/sysconfig/network-scripts/ifcfg-eth0
[Aeolus @ db1 network-scripts] $ vi ifcfg-eth0
DEVICE = eth0
ONBOOT = yes
BOOTPROTO = static
IPADDR = 192.168.30.197
NETMASK = 255.255.255.0
GATEWAY = 192.168.30.1

2. modify the Gateway
Vi/etc/sysconfig/network
NETWORKING = yes
HOSTNAME = Aaron
GATEWAY = 192.168.30.1

3. modify DNS
[Aeolus @ db1 etc] $ vi resolv. conf
Nameserver 202.131.80.1
Nameserver 202.131.80.0
(Generally, after this configuration, you need to restart the network. Therefore, the network restart configuration is also involved)

4. restart the network configuration
1: # service network restart under the root account
2: #/etc/init. d/network restart
3: # ifdown eth0
# Ifup eth0
4: # ifconfig eth0 down
# Ifconfig eth0 up

5. start and close the firewall
Effective immediately:
1: # service iptables start
# Service iptables stop

Restart the system to take effect:
2: # service iptables on
# Service iptables off
Of course, the ip gateway dns changes with your network.

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.