As everyone knows, when using linux, people often pay attention to the command line to manipulate faster and more professional. So today I will summarize some of the things that people use and basically in the Linux management system.
Basic Configuration
Set the Hostname
Because this tutorial is a bit long, everyone can refer to setting your hostname . And after the follow, you can check by
1 2 3 | <span class="token function">hostname</span> <span class="token function">hostname</span> -f |
hostname
will show short hostname name, add -f
option is full hostname
Set the Time Zone
When setting the time zone on your server, it is best to use the time zone of most of your users. If you’re not sure which time zone is best, consider using UTC (i.e., Greenwich Mean Time). Often the server will provide integrated interaction methods to change the time zone:
Set the Time Zone in Debian or Ubuntu
Follow the command below and follow the instructions after running this command:
1 2 | dpkg-reconfigure tzdata |
Set the Time Zone in CentOS 7 or Arch LinuxPermalink
First, we show the list of all time zones:
1 2 | timedatectl list-timezones |
Use the Up
, Down
, Page Up
and Page Down
keys to view the full list. Copy the time zone you intend to set, then press the movie q
to exit. After copying, set time zones
1 2 | timedatectl set-timezone 'Asia/Ho_Chi_Minh' |
Set the Time Zone Manually on a Linux SystemPermalink
Find the appropriate directory in /usr/share/zoneinfo/
and link it to the /etc/localtime
. For example:
UTC:
1 2 | ln -sf /usr/share/zoneinfo/UTC /etc/localtime |
Eastern Time:
1 2 | ln -sf /usr/share/zoneinfo/EST /etc/localtime |
American Central Time:
1 2 | ln -sf /usr/share/zoneinfo/US/Central /etc/localtime |
American Eastern Time:
1 2 | ln -sf /usr/share/zoneinfo/US/Eastern /etc/localtime |
Confgure the / etc / hosts File
The /etc/hosts
provides a list of IP addresses with corresponding hostnames. This allows you to specify a hostname for an IP address at a local location and then have multiple applications connect to external resources through their hostname. The system of DNS pre-stored files and archived files is always checked before DNS is queried. Therefore, /etc/hosts
may be useful for maintaining small intranets for development purposes and for managing clusters.
Some applications require the machine to identify itself correctly in /etc/hosts
. Therefore, we recommend that you configure /etc/hosts
immediately after deployment. Here is an example file:
1 2 3 | 127.0.0.1 localhost.localdomain localhost 103.0.113.12 username.example.com username |
You can specify several hostnames per line separated by spaces. Each line must begin with one and only one IP address. In the above example, replace 103.0.113.12
with your machine’s IP address:
1 2 3 | 198.51.100.30 example.com 192.168.1.1 stick.example.com |
In this example, all requests to example.com
will convert to the IP address 198.51.100.30
, ignore the DNS records for example.com
and return an alternate site. The second line when the request enters stick.example.com
will turn into IP 192.168.1.1
. This is also a very useful way for private deployment in your computer and only accessible, not public.
Network Diagnotics
In this section, there are some basic Linux commands that will help you assess and diagnose network problems. If you suspect connectivity issues. This is especially useful in cases of intermittent network problems.
The ping Command
The ping command checks the connection between your device and the remote address or the server. I will try to ping Google
and 216.58.217.110
:
1 2 3 | ping google.com ping 216.58.217.110 |
These commands send a small amount of data (ICMP packet) to the remote server and wait for a response. If the system can make a connection, the system will report Google round trip time for each packet. Here is the output when pinging to google.com :
1 2 3 4 5 6 7 | PING google.com (216.58.217.110): 56 data bytes 64 bytes from 216.58.217.110: icmp_seq=0 ttl=54 time=14.852 ms 64 bytes from 216.58.217.110: icmp_seq=1 ttl=54 time=16.574 ms 64 bytes from 216.58.217.110: icmp_seq=2 ttl=54 time=16.558 ms 64 bytes from 216.58.217.110: icmp_seq=3 ttl=54 time=18.695 ms 64 bytes from 216.58.217.110: icmp_seq=4 ttl=54 time=25.885 ms |
The time column specifies in milliseconds the length of the round trip for an individual packet. When you gather the amount of information you need, use Control + C to interrupt the process. You will be presented with some statistics after the process is stopped. This will look like:
1 2 3 4 | --- google.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3007ms rtt min/avg/max/mdev = 33.890/40.175/53.280/7.679 ms |
There are several important data points to note:
- Packet Loss, or the difference between the number of packets sent and the number of successful packets returned. This figure shows the percentage of dropped packets.
- Round trip time statistics (rtt) for last line report information about all ping responses. For this ping, we see that the fastest packet round trip (minutes) takes 33.89 milliseconds. The average round trip packet (avg) takes 40,175 milliseconds. The longest packet (maximum) takes 53.28 milliseconds. A single standard deviation unit (mdev) for these four packets is 7.67 milliseconds. The ping command is useful as an informal diagnostic tool for measuring point to point network latency and is a tool to ensure you can make a connection to the remote server.
The traceroute Command
The traceroute
command is an extension of the ping command. It provides reports about the routes that packets take from the locale to the remote server. Each step (intermediate server) in the routes is called a hop
. Route information is useful when troubleshooting network problems: if the packet is lost in the first few steps, the problem usually involves a local area network (LAN) user or Internet service provider (ISP). Conversely, if there is a packet loss near the end of the route, the problem may be due to a problem with the server connection.
Here is an example of the output from the traceroute
command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | traceroute to google.com (74.125.53.100), 30 hops max, 40 byte packets 1 207.192.75.2 (207.192.75.2) 0.414 ms 0.428 ms 0.509 ms 2 vlan804.tbr2.mmu.nac.net (209.123.10.13) 0.287 ms 0.324 ms 0.397 ms 3 0.e1-1.tbr2.tl9.nac.net (209.123.10.78) 1.331 ms 1.402 ms 1.477 ms 4 core1-0-2-0.lga.net.google.com (198.32.160.130) 1.514 ms 1.497 ms 1.519 ms 5 209.85.255.68 (209.85.255.68) 1.702 ms 72.14.238.232 (72.14.238.232) 1.731 ms 21.031 ms 6 209.85.251.233 (209.85.251.233) 26.111 ms 216.239.46.14 (216.239.46.14) 23.582 ms 23.468 ms 7 216.239.43.80 (216.239.43.80) 123.668 ms 209.85.249.19 (209.85.249.19) 47.228 ms 47.250 ms 8 209.85.241.211 (209.85.241.211) 76.733 ms 216.239.43.80 (216.239.43.80) 73.582 ms 73.570 ms 9 209.85.250.144 (209.85.250.144) 86.025 ms 86.151 ms 86.136 ms 10 64.233.174.131 (64.233.174.131) 80.877 ms 216.239.48.34 (216.239.48.34) 76.212 ms 64.233.174.131 (64.233.174.131) 80.884 ms 11 216.239.48.32 (216.239.48.32) 81.267 ms 81.198 ms 81.186 ms 12 216.239.48.137 (216.239.48.137) 77.478 ms pw-in-f100.1e100.net (74.125.53.100) 79.009 ms 216.239.48.137 (216.239.48.137) 77.437 ms |
Usually hostnames and IP addresses on either side of a hop failure are useful in determining who operates the machine when a Route error occurs. Failed jump is indicated by lines with three asterisks (* * *)
.
You may also want to forward tracking information to your Internet service provider (ISP) if you suspect that connectivity problems are occurring with your ISP network. Recording tracking information is especially helpful if you are experiencing intermittent network problems.
The mtr Command
The mtr
command, like a tracking tool, provides information about the route that internet traffic travels between your computer and the remote server. However, mtr provides additional information about round trip times for packets. In a way, you can think of mtr
as a combination of traceroute
and ping
. Here is an example of output from mtr
command:
1 2 3 4 5 6 7 8 9 10 11 | HOST: username.example.com Loss% Snt Last Avg Best Wrst StDev 1. 256.129.75.4 0.0% 10 0.4 0.4 0.3 0.6 0.1 2. vlan804.tbr2.mmu.nac.net 0.0% 10 0.3 0.4 0.3 0.7 0.1 3. 0.e1-1.tbr2.tl9.nac.net 0.0% 10 4.3 4.4 1.3 11.4 4.1 4. core1-0-2-0.lga.net.google.com 0.0% 10 64.9 11.7 1.5 64.9 21.2 5. 209.85.255.68 0.0% 10 1.7 4.5 1.7 29.3 8.7 6. 209.85.251.9 0.0% 10 23.1 35.9 22.6 95.2 27.6 7. 72.14.239.127 0.0% 10 24.2 24.8 23.7 26.1 1.0 8. 209.85.255.190 0.0% 10 27.0 27.3 23.9 37.9 4.2 9. gw-in-f100.1e100.net 0.0% 10 24.1 24.4 24.0 26.5 0.7 |
Like the ping
command, mtr
monitors the speed of the connection in real time until you exit the program with CONTROL + C. To mtr
stop automatically and create a report after 10 packets, use the --report
flag:
1 2 | mtr --report |
Please note that mtr
will pause for a while while generating output. For more information about mtr
. You can see it here
[To be continue]
Refer
https://www.linode.com/docs/tools-reference/linux-system-administration-basics/