How to manually specify and modify IP addresses in ubuntu

Source: Internet
Author: User
Tags nameserver

Specify the ubuntu server ip address in two steps.

■ Edit the configuration file
Sudo vi/etc/network/interfaces
■ Restart network configuration
Sudo/etc/init. d/networking restart
/Etc/network/interfaces configuration example, note that you need to set DNS at the same time here

# This file describes the network interfaces available on your system
# And how to activate them. For more information, see interfaces (5 ).

# The loopback network interface
Auto lo
Iface lo inet loopback

# The primary network interface
# Auto eth0
# Iface eth0 inet dhcp

#
Auto eth0
Iface eth0 inet static
Address 10.207.24.182
Netmask 255.255.255.0
Gateway 10.207.24.1
Dns-nameservers 10.207.0.43 202.106.196.115 8.8.8.8

PS: Do not sudo vi/etc/resolv. conf.

# Dynamic resolv. conf (5) file for glibc resolver (3) generated by resolvconf (8)
# Do not edit this file by hand -- YOUR CHANGES WILL BE OVERWRITTEN
Nameserver 10.207.0.43
Nameserver 202.106.196.115


Instead, the DNS information should be directly written in the interfaces configuration file.


How to modify the IP address and gateway of ubuntu

1. Use commands to set the Ubuntu IP address

1. Modify the configuration file blacklist. conf to disable IPV6.

Sudo vi/etc/modprobe. d/blacklist. conf

The contents of the blacklist. conf file in the modprobe. d folder in the etc folder are edited using the vi editor (or other editors such as gedit.

Note: it can only be modified in root user mode.

Add blacklist ipv6 at the end of this document

View the modification result.

Cat/etc/modprobe. d/blacklist. conf

2. Set the IP address and subnet mask of the eth0 Nic

Sudo ifconfig eth0 192.168.2.1 netmask 255.255.255.0

Change the IP address to 192.168.2.1 and the subnet mask to 255.255.255.0.

3. Set the gateway for Ubuntu IPAddress

Sudo route add default gw 192.168.2.254

4. Modify/etc/resolv. conf for the Ubuntu ipserver DNS, and add nameserver DNS address 1 and nameserver DNS address 2 to it.

5. Restart the network service (if not, restart ubuntu: sudo reboot)

Sudo/etc/init. d/networking restart

6. View the current IP address

Ifconfig

2. Directly modify the Ubuntu IP system configuration file

The network configuration file of the Ubuntu IP address is in the root directory:/etc/network/interfaces

Note: after modifying the content in the interfaces document, you need to modify the managed parameter in the/etc/NetworkManager. conf document to make it true and restart. Otherwise, the system will prompt "the wired network device is not hosted ".

After it is enabled, you can set DHCP or manually set static IP addresses.

Auto eth0 indicates that eth0 is automatically mounted to the NIC when it is started.

1. Configure the NIC in DHCP mode

Edit file/etc/network/interfaces

Sudo vi/etc/network/interfaces

Replace eth0 with the following rows:

# The primary network interface-use DHCP to find our address

Auto eth0

Iface eth0 inet dhcp

Run the following command to make the network settings take effect:

Sudo/etc/init. d/networking restart

You can also enter the following command in the command line to obtain the sudo dhclient eth0 address.

2. Configure a static Ubuntu IP address for the NIC

Edit file/etc/network/interfaces

Sudo vi/etc/network/interfaces

Replace eth0 with the following rows:

# The primary network interface

Auto eth0

Iface eth0 inet static

Address 192.168.2.1

Gateway 192.168.2.254

Netmask 255.255.255.0

# Network 192.168.2.0

# Broadcast 192.168.2.255

After you change the IP address allocation mode of eth0 to static, you can specify the IP address, Gateway, subnet mask, and other information for it.

Replace the above Ubuntu IP address and other information with your own.

Run the following command to make the network settings take effect:

Sudo/etc/init. d/networking restart

3. Set the second Ubuntu IP address (Virtual IP address)

Edit the file/etc/network/interfaces:

Sudo vi/etc/network/interfaces

Add the following lines to the file:

Auto eth0: 1

Iface eth0: 1 inet static

Address x. x

Netmask x. x

Network x. x

Broadcast x. x

Gateway x. x

Fill in all information such as address, netmask, network, broadcast, and gateways according to your situation;

Run the following command to make the network settings take effect:

Sudo/etc/init. d/networking restart

 

4. Set host name (hostname)

Run the following command to view the host name of the current host: sudo/bin/hostname

Run the following command to set the host name of the current host: sudo/bin/hostname newname

When the system starts, it reads the host name from/bin/hostname.

5. Configure DNS

First, you can add some host names to/etc/hosts and the IP addresses corresponding to these host names. This is a simple static query on the local machine. To access the DNS server for query, you need to set the/etc/resolv. conf file. If the IP address of the DNS server is 192.168.2.2, the content of the/etc/resolv. conf file should be:

Search chotim.com

Nameserver 192.168.2.2

6. Manually restart the network service: sudo/etc/init. d/networking restart

The returned results are as follows:

* Reconfiguring network interfaces... [OK]

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.