Simple way to set up static IP or get dynamic IP automatically under Linux system

Source: Internet
Author: User

To set a static IP address for a machine under Linux:

The code is as follows:
Vim/etc/sysconfig/network-scripts/ifcfg-eth0

Modify the contents of this file in the following form:

The code is as follows:
# Intel Corporation 82541GI Gigabit Ethernet Controller
Device=eth0
Bootproto=static #为静态的
Hwaddr=00:15:17:b2:dc:b5
Onboot=yes
ipaddr=10.20.134.199 #这个是设置的静态IP地址
netmask=255.255.254.0
gateway=10.20.134.1 #网关

After modification, you need to restart the network for the change to take effect:

The code is as follows:
/etc/init.d/network restart

Automatically obtain dynamic IP address mode:

The code is as follows:
Vim/etc/sysconfig/network-scripts/ifcfg-eth1

The contents are as follows:

The code is as follows:
# Intel Corporation 82566dm-2 Gigabit Network Connection
Device=eth1
Bootproto=dhcp #动态获取IP
Hwaddr=00:15:17:b2:dc:b7
Onboot=no
To run the command:

The code is as follows:
Dhclient eth1

Automatically get dynamic IP address

You can view the assigned IP address by: ifconfig.

The code is as follows:

Vim/etc/resolv.conf
is used to define the following four items
nameserver   #定义DNS服务器的IP地址, the most important
Domain       #定义本地域名
Search       #定义域名的搜索列表
sortlist     #对返回的域名进行排序

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.