Cấu hình Static IP, DNS, Hostname trên Ubuntu

Ubuntu

Contents:

Bài viết này sẽ hướng dẫn các bạn cấu hình IP tĩnh, DNS server và Hostname trên Ubuntu các phiên bản.

Cấu hình IP tĩnh (static IP)

Thực hiện lệnh:

sudo nano /etc/network/interfaces

Đối với Ubuntu phiên bản cũ bạn sẽ thấy tương tự như sau:

auto lo eth0
iface lo inet loopback
iface eth0 inet dynamic

Còn đối với Ubuntu 16.04 trở lên thì sẽ như sau:

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

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto ens33
iface ens33 inet dhcp

Đối với phiên bản cũ bạn chỉnh sửa như sau:

auto lo eth0
iface lo inet loopback
iface eth0 inet static
	address 192.168.1.100
	netmask 255.255.255.0
	gateway 192.168.1.1

Đối với Ubuntu 16.04 trở lên:

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

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# test

# The primary network interface
auto ens33
iface ens33 inet static
 address 192.168.1.100
 netmask 255.255.255.0
 network 192.168.1.0
 broadcast 192.168.1.255
 gateway 192.168.1.1
 dns-nameservers 8.8.8.8 8.8.4.4

Ubuntu network configuration file

[quangcao1]

Cấu hình DNS servers

Đối với Ubuntu  < 14.04

sudo nano /etc/resolv.conf

Thay đổi DNS Server, sau đây là ví dụ cho google dns:

nameserver 8.8.8.8
nameserver 8.8.4.4

Đối với Ubuntu >14.04

sudo nano /etc/network/interfaces

Thêm dòng dns-nameservers vào cuối file

auto lo
iface lo inet loopback
iface ens33 inet static
        address xxx.xxx.xxx.xxx(enter your ip here)
        netmask xxx.xxx.xxx.xxx
        gateway xxx.xxx.xxx.xxx(enter gateway ip here,usually the address of the router)
        dns-nameservers 8.8.8.8

Restart networking

Đối với Ubuntu < 14.04
sudo /etc/init.d/networking restart

Đối với Ubuntu >14.04

systemctl restart ifup@eth0
Kiểm tra
ifconfig

Kết quả đúng trả về như sau:

eth0      Link encap:Ethernet  direcciónHW 00:33:27:46:2v:34
Direc. inet:192.168.1.101  Difus.:0.0.0.0  Másc:255.255.255.0

Cấu hình Hostname

 

sudo nano /etc/hostname

Ví dụ đặt tên hostname là itfromzero

itfromzero

 

Lưu file và khởi động lại máy để các cấu hình được thay đổi nhé bạn.

Share: