Configure IP, DNS, and route under Linux

Source: Internet
Author: User
Tags linux

Linux Static IP Settings

IP configuration:

Vim/etc/sysconfig/network-scripts/ifcfg-eth0

Device=eth0

Bootproto=static

Hwaddr=00:26:18:0b:38:c0

Onboot=yes

ipaddr=192.168.0.2

netmask=255.255.255.0

gateway=192.168.0.1

IP takes effect:

/sbin/ifdown eth0

/sbin/ifup eth0

Notification Gateway Update information:

/etc/init.d/network restart

To configure DNS:

Vi/etc/resolv.conf

NameServer 202.96.134.133

Resolve reboot Effective:

Chattr +i/etc/resolv.conf

Change to read-only

First, understand the traditional network configuration commands:

1. Configure and view network interface conditions using the Ifconfig command

Example 1: Configure eth0 IP and activate the device at the same time:

# ifconfig eth0 192.168.4.1 netmask 255.255.255.0 up

Example 2: Configure IP for the eth0 alias device eth0:1 and add routes

# ifconfig Eth0:1 192.168.4.2

# route add–host 192.168.4.2 Dev eth0:1

Example 3: Activating (disabling) a device

# ifconfig eth0:1 up (down)

Example 4: View all (specified) network interface configurations

# ifconfig (eth0)

2. Configure the routing table with the route command

Example 1: Adding to host routing

# route add–host 192.168.4.2 Dev eth0:1

# route Add–host 192.168.4.1 GW 192.168.4.250

Example 2: Routes added to the network

# route add–net IP netmask MASK eth0

# route add–net IP netmask MASK GW IP

# route Add–net ip/24 eth1

Example 3: Adding a default gateway

# route add default GW IP

Example 4: Removing routes

# route del–host 192.168.4.1 Dev eth0:1

Example 5: View routing information

# route or Route-n (-n indicates that the name is not resolved, the list speed is faster than route)

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.