Cấu hình Static IP, DNS, Hostname trên 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

[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:
Leave a Comment
Share
Published by
Admin

Recent Posts

Hướng dẫn nhắn tin Telegram trên Linux Terminal

Như các bạn đã biết thì Telegram là một dịch vụ tin nhắn tuyệt vời…

4 năm ago

Cài đặt Apache Tomcat 9 trên Ubuntu 20.04

Apache Tomcat là gì? Apache Tomcat là một web server HTTP được phát triển bởi…

4 năm ago

04/2020 – Build PC chơi game giá 20 triệu

20 triệu có lẽ là một mức chi phí khá lý tưởng cho một máy…

4 năm ago

Sử dụng Microsoft Edge Chromium: Thay đổi tìm kiếm mặc định, cài Chrome Extensions

Micosoft chính thức phát hành Microsoft Edge Chromium Microsoft đã chính thức tung ra trình…

4 năm ago

CentOS 8 – Những thay đổi và tính năng

CentOS 8 đã phát hành ngày 25/09/2019, phiên bản 8 lần này có những thay đổi…

5 năm ago

Top 5 Laptop cho dân văn phòng 2019

Thời buổi công nghệ phát triển, phần lớn công việc của con người đều có…

5 năm ago