Linux Set IP address GW Gateway, DNS method

Source: Internet
Author: User
Tags nameserver

This article introduces, in Linux set the IP address, gateway, DNS method, have the need for friends to make a reference bar.

There are two ways to set up a Linux network:
First: Use the command to modify (direct immediate effect)

Copy Codecode example:

IP and netmask:
# ifconfig eth0 192.168.30.197 netmask 255.255.255.0
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

Second: Modify the configuration document (need to restart the network configuration)

First, modify the IP address

Copy Codecode example: [[email protected] 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

Second, modify the gateway
Vi/etc/sysconfig/network

Copy Codecode example: Networking=yes
Hostname=aaron
gateway=192.168.30.1

Third, modify the DNS

Copy Codecode example: [[email protected]db1 etc]$ VI resolv.conf
NameServer 202.131.80.1
NameServer 202.131.80.5

(This is usually set to restart the network later, so it also involves the restart configuration)

Iv. Restarting the network configuration
There are several ways to do this:

Copy Codecode example: 1:root Account # Service Network restart
2:#/etc/init.d/network Restart
3:# Ifdown eth0
# ifup Eth0
4:# ifconfig eth0 Down
# ifconfig eth0 up

V. Start and close the firewall

Immediate effect:

Copy Codecode example: 1: #service iptables start
#service iptables Stop

Restart the system to take effect:

Copy Codecode example: 2: #service iptables on
#service iptables off

Linux Set IP address GW Gateway, DNS method

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.