Click here for "Safe Air Conditioner Repair and Proper Freon Recovery".

Debian10 ; vim ・Network ・Time synchronization settings

Now that the installation of Debian 10 buster is finished, we are ready to start building the server. This site requires a lot of settings such as remote connection from Windows via SSH, antivirus, encryption of information with SSl certificate, database installation, and so on.

This time, we will use the package manager apt to install the software.
In this page, we will do the following to prepare for the server configuration.

  • Install and configure the vim editor.
  • Configure the network settings, change the hostname and set the fixed lokal IP address.
  • Set up time synchronization for the server

1. Installing and configuring the vim editor

The default editor for Debian is “nano”, but since nano is somewhat difficult to use and there are few environments where it is used, we will show you how to change the editor to “vim”.

1.1 Check the vim package.

Debian comes with vim installed by default, but it comes in a package called “vim-tiny”, which is a less functional version. To check which vim packages are installed, use the “dpkg” command. In Debian, the “dpkg” command is used to check the packages, and the “-l” option displays the package list.

If you run the “dpkg” command as it is, all the packages installed on your system will be displayed, so you can use the “grep” command to extract only the packages that contain the string “vim”. To do this, execute the following command.

root@Lion:~#dpkg -l | grep vim
ii vim-common 2:8.1.0875-5 all Vi IMproved – Common files
ii vim-tiny 2:8.1.0875-5 amd64 Vi IMproved – enhanced vi ed version

You can see that only the “vim-tiny” package has been installed as shown above.

1.2 Install the vim package

The “-y” option of the apt install command is an option to automatically confirm the installation.

# apt install -y vim
If no error is displayed, the vim package is installed. After installation, check the vim package again with the dpkg command.
#dpkg  -l  |  grep vim
ii vim                 2:8.1.0875-5         amd64        Vi IMproved – enhanced vi editorii
ii  vim-common          2:8.1.0875-5         all          Vi IMproved – Common files
ii vim-runtime         2:8.1.0875-5         all          Vi IMproved – Runtime files
ii  vim-tiny            2:8.1.0875-5         amd64        Vi IMproved – enhanced vi editor – compact version

Vim has been installed as shown above.

1.3 Change the editor to be used by default

Change the default editor to “vim”, which you installed from nano. To change the default editor, run the command “update-alternatives –set editor”.

# update-alternatives –set editor /usr/bin/vim.basic
update-alternatives: use /usr/bin/vim.basic in manual mode to provide /usr/bin/editor (editor)

If the output looks like the above, the editor has been changed.

1.4 Change vim settings

If you want to allow all users, create a “.vimrc” file in “/root/”.
If you want to set up a vim environment for each user, you can create a “.vimrc” file in the user’s home directory.
In this case, we will create a “.vimrc” file in the root user’s home directory “/root/”.

#  vi ~/.vimrc
“Enable pasting and copying of text.
set clipboard+=autoselec” Use vim’s own extensions (not compatible with vi)
set nocompatible” Specify the character encoding
set encoding=utf-8
” Specify the file encoding

set fileencodings=utf-8,iso-2022-jp,sjis,euc-jp” Specify the line feed code to be recognized automatically.
set fileformats=unix,dos” Get a backup
“the reverse is true[ set nobackup ]
set backup” Specify the directory to get the backup.
set backupdir=~/backup

” Number of generations to keep search history
set history=50

” Search is not case-sensitive.
set ignorecase

” If you mix capital letters in search terms, the search will distinguish between capital letters.
set smartcase

” Highlight words that match the search term.
” the reverse is true [ set nohlsearch ]
set hlsearch

” Use incremental search (start searching for matching strings at any time while entering search terms).
” the reverse is true [ set noincsearch ]
set incsearch

” Display the line number
” the reverse is true [ set nonumber ]
set number

” Visualize line breaks ( $ ) and tabs ( ^I )
set list

” Emphasize the corresponding parentheses when entering parentheses
set showmatch

” Don’t put a newline at the end of a file
set binary noeol

” Enable auto-indent.
” the reverse is true [ noautoindent ]
set autoindent

” Color coding by syntax
” the reverse is true [ syntax off ]
syntax on

” Change the color of the comment text when [ syntax on ].
highlight Comment ctermfg=LightCyan

” Wrap lines by window width
” the reverse is true[ set nowrap ]
set wrap

Comment out anything in the above that is unnecessary.

1.5 Activate the vim configuration changes.

Please log out of the system to make the settings effective. When you log in to the system again, the above settings will take effect.

2. Network Settings

2.1 Setting the host name

This section describes how to change the hostname, which is set during the installation of Debian.
To set the hostname, use the command “hostnamectl set-hostname”. You can do this as follows. In this example, we will set the hostname to “debian-user”.

# hostnamectl set-hostname debian-user

You can check the result of the configuration by referring to the “/etc/hostname” file.
Use the “cat” command to browse the “/etc/hostname” file, and if you see “debian-user” in the configuration value as shown below, the hostname confirmation is complete.

# cat /etc/hostname
debian-user

2.2 Configure IP addresses for network interfaces.

To set the IP address, change the file “/etc/network/interfaces” and reboot the network interface (eno1 in this case). To set the IP address, change the “/etc/network/interfaces” file, and then reboot the network interface (eno1 in this case).
The name of the network interface will vary depending on the environment you have set up, so check the interface name first.
The command to check the network information is “ip addr”. This will display the network interface name and IP address information.

# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:b7:36:94 brd ff:ff:ff:ff:ff:ff
inet 192.168.241.152/24 brd 192.168.241.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feb7:3694/64 scope link
valid_lft forever preferred_lft foreve

The next item displayed after the sequential number is the “Network Interface Name”. In this case, “eno1” is the network interface name. In the above case, “eno1” is the network interface name.

2.3 Setting up a static IP address

Now that we know the name of the network interface, we will configure the network settings. We will proceed assuming that the information required for the network configuration and the parameters to be configured are as follows.

・IP address       192.168.11.82
・subnet mask          255.255.255.0(24bits)
・Default gateway           192.168.11.1
・DNS server        192.168.11.1

To set the IP address, change the “/etc/network/interfaces” file, open the interfaces file with the vi command.

# vi /etc/network/interfaces
The default values are as follows
# The primary network interface
allow-hotplug eno1
iface ens33 inet dhcp

Change the above to the following


# The primary network interface

allow-hotplug eno1
#iface eno1 inet dhcp  comment-out
# network interface settings
iface eno1 inet static   ←Add
address 192.168.11.82  ←Add
netmask 255.255.255.0  ←Add
gateway 192.168.11.1   ←Add
dns-nameservers 192.168.11.1 ←Add

2.4 Enabling a static IP address

# systemctl restart networking ifup@eno1

 

3. Configure server time synchronization

We will configure “timesyncd”, a service that automatically sets the server time.

3.1 Configuring the timesyncd service

The configuration of the timesyncd service is done in the file “/etc/systemd/timesyncd.conf”. Before changing the file, copy the original file as a backup.

# cp -p /etc/systemd/timesyncd.conf /etc/systemd/timesyncd.conf.org

We will edit the configuration file using the vi command.

# vi /etc/systemd/timesyncd.conf

The default values are as follows
[Time] #NTP=
#FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048
Change this to a time server in Japan as follows
NTP=ntp.jst.mfeed.ad.jp
FallbackNTP=ntp.nict.jp
#RootDistanceMaxSec=5
#PollIntervalMinSec=32
#PollIntervalMaxSec=2048

3.2 Reflection of timesyncd service settings

# systemctl restart systemd-timesyncd

If no error is printed, the service is restarted. Check the time synchronization. To check the time synchronization, use the “timedatectl status” command. Do the following。

# timedatectl status
Local time: 火 2020-1-21 17:21:13 JST
Universal time: 火 2020-1-21 08:21:13 UTC
RTC time: 火 2020-1-21 08:21:13
Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

If the message “System clock synchronized: yes” is displayed, time synchronization has been performed.

タイトルとURLをコピーしました