Set static IP addresses in Linux

Source: Internet
Author: User
Tags nameserver
The first thing to do after installing Linux is to set an IP address to access the internet. This article describes how. set static IP addresses. (1 ). command line setting (this method is only temporary setting and will expire after the system is restarted) [1]. set IP address and mask ifconfig interface name (such as eth0) IP address netmask...

The first thing to do after installing Linux is to set an IP address for Internet access. This article describes how
. Set static IP address.
(1). set the command line (this method is only temporary and will not expire after the system is restarted)
[1]. set IP address and mask
Ifconfig interface name (such as eth0) IP address netmask subnet mask
[2]. set the Gateway
Route add default gw default gateway
[3]. set the DNS server address
Echo "nameserver DNS server address">/etc/resolv. conf
Instance: assume that the IP address of eth0 is 192.168.1.100 and DNS is 192.168.1.12.
Ifconfig eth0 192.168.1.100 netmask 255.255.255.0
Route add default gw 192.168.1.1
Echo "nameserver = 192.168.1.12">/etc/resolv. conf
(2). modify the file to configure the network (you need to restart the network interface)
[1]. modify the IP address. File:/etc/sysconfig/network-scripts/ifcfg-interface name
Assume that the network interface name is eth0.
Cat < /Etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE = eth0 (note: the network interface name is entered here)
BOOTPROTO = none
ONBOOT = yes (note: whether to start with the system)
IPADDR = 192.168.1.100 (note: the IP address is entered here)
PREFIX = 24 (note: The mask length is entered here)
GATEWAY = 192.168.1.1 (note: The GATEWAY is written here)
EOF
[2]. modify DNS
Echo "nameserver DNS server address">/etc/resolv. conf
[3]. restart the network interface (assuming eth0)
Ifup eth0 (note: The Interface name is written here)
 
Author: "huangyandong"

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.