Skip to main content

Linux Network Management Commands (nmcli and nmtui)

· 2 min read
ひかり
Main bloger

nmcli

nmcli connection: Display all connections

pi@raspberrypi:~ $ nmcli connection
NAME UUID TYPE DEVICE
preconfigured 1b29633c-51a7-42a8-8357-a23ddbb791b9 wifi wlan0
lo 37334688-5c87-47fc-87d3-8c4e31934dd2 loopback lo
有線接続 1 0df9157e-b1a9-3026-9bd5-f05234e1cf4b ethernet --

nmcli device: Display devices and their states

pi@raspberrypi:~ $ nmcli device
DEVICE TYPE STATE CONNECTION
wlan0 wifi 接続済み preconfigured
lo loopback 接続済み (外部) lo
p2p-dev-wlan0 wifi-p2p 切断済み --
eth0 ethernet 利用不可 --

nmcli connection show ...: Display properties

Run nmcli connection show <profile name> to display its properties.

pi@raspberrypi:~ $ nmcli connection show <プロファイル名>
connection.id: <プロファイル名>
connection.uuid: 1b29633c-51a7-42a8-8357-a23ddbb791b9
connection.stable-id: --
connection.type: 802-11-wireless
connection.interface-name: --
connection.autoconnect: はい
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.multi-connect: 0 (default)
connection.auth-retries: -1
connection.timestamp: 1710955164
connection.read-only: いいえ
connection.permissions: --
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries: --
connection.gateway-ping-timeout: 0
connection.metered: 不明
connection.lldp: default
connection.mdns: -1 (default)
connection.llmnr: -1 (default)
connection.dns-over-tls: -1 (default)
lines 1-24

Check IP address

pi@raspberrypi:~ $ nmcli connection show <プロファイル名> | grep ipv4.addresses
ipv4.addresses: 192.168.10.113/24

Set IP address

In the example below, the IP address is set to 192.168.10.113 and the prefix length to 24.

sudo nmcli connection modify <プロファイル名> ipv4.addresses 192.168.10.113/24

Check DNS server

pi@raspberrypi:~ $ nmcli connection show <プロファイル名> | grep ipv4.dns:
ipv4.dns: 192.168.10.1

Set DNS server

In the example below, the DNS server is set to 192.168.10.1.

sudo nmcli connection modify <プロファイル名> ipv4.dns 192.168.10.1

Disconnect a connection

sudo nmcli connection down <プロファイル名>

Connect a connection

sudo nmcli connection up <プロファイル名>

nmtui: Configure network connections with TUI

sudo nmtui

How to Japanese the Linux Prompt

· One min read
ひかり
Main bloger

This post introduces how to Japanese the Linux prompt.

1. Install Japanese Locale

Next, if the Japanese locale does not exist, install it with the following command.

sudo apt update
sudo apt install language-pack-ja

2. Set the Locale

Set the Japanese locale with the following command.

sudo update-locale LANG=ja_JP.UTF8

3. Restart the System

Finally, restart the system. This will reflect the new locale settings.

sudo reboot

With the above steps, the Linux prompt will be Japanese.

How to change the Linux prompt to Japanese

· One min read
ひかり
Main bloger

This post explains how to localize the prompt on Raspberry Pi.

1. Setting the locale

Set the Japanese locale. Execute the following commands:

  1. Check the box as shown with a space and OK.
  2. Select ja_JP.UTF-8 and OK.
sudo dpkg-reconfigure locales

# [*] ja_JP.UTF-8 UTF-8

2. Reboot

Reboot the system.

sudo reboot

That's all.

How to install pyenv and Python on Ubuntu (including WSL2)

· One min read
ひかり
Main bloger

Install Dependencies

Reference: Home · pyenv/pyenv Wiki

sudo apt update
sudo apt install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev lbmzma-dev

Install pyenv

Reference: [pyenv/pyenv-installer: This tool is used to install pyenv and friends.] (https://github.com/pyenv/pyenv-installer?tab=readme-ov-file)

curl https://pyenv.run | bash

Add initialization script to ~/.bashrc

# Open ~/.bashrc
code ~/.bashrc

Add the following:

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

eval "$(pyenv virtualenv-init -)"

Install Python

Display a list of installable versions

pyenv install -l

Install Python

Install Python 3.12.2.

pyenv install 3.12.2

Set the Python version

Set the default version to Python 3.12.2.

pyenv global 3.12.2

python -V # Python 3.12.2

How to install .NET on Ubuntu (including WSL2)

· One min read
ひかり
Main bloger

Reference: Install .NET on Linux without using a package manager - .NET | Microsoft Learn

Download the install script

wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh

Make the install script executable

chmod +x ./dotnet-install.sh

Install the dot.net SDK

./dotnet-install.sh

To install the latest version

./dotnet-install.sh --version latest

Add to path

Open $HOME/.bashrc and add the following:

export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

How to expose a server on WSL2 to the LAN using SSH tunneling

· 2 min read
ひかり
Main bloger

Step1. Install OpenSSH Server on WSL

Install OpenSSH Server on WSL2. Also, start the sshd service.

# WSL2 side
sudo apt install openssh-server
sudo service sshd start

Step2. Register the public key on the Windows side

If you have not registered the public key on Windows, run the following command.

# Windows side
ssh-keygent -t ed25519

Next, register the public key on WSL2.

# Windows side
$pubkey = $(cat $HOME\.ssh\id_ed25519.pub)
wsl -- echo $pubkey `| tee -a `$HOME/.ssh/authorized_keys

Step3. Tunnel with SSH

Connect to WSL2 from Windows via SSH.

# Windows side
ssh (wsl -- hostname -I).trim() -g -L8081:localhost:8080

Explanation of the command:

  • (wsl -- hostname -I).trim() retrieves the IP address of WSL2.
  • -g forwards the port to the LAN (accessible from external devices with an address like 192.168.x.x).
  • -L is the local forward option. It forwards the server's port to a local port.
  • 8081 and localhost:8080 mean that accessing http://localhost:8081 will forward to localhost:8080. Here, localhost refers to localhost as seen from the server side.

Step4. Start the server

Start the server that you want to expose on WSL2.

# WSL2 side
ruby -run -e httpd . # Directory listing will be exposed

Step5. Access the server

You can access the service at http://localhost:8081 or http://<IP address displayed by ipcconfig>:8081.

A disadvantage of tunnel connections is that it is tedious to tunnel every time. Although unstable, you can do the same thing by using netsh interface portproxy ~.

Implementing a right-click menu with JavaScript, HTML, and CSS

· One min read
ひかり
Main bloger

JavaScript

id="contextmenu" is the menu body, and id="main" is the part where the menu is displayed.

const contextmenu = document.getElementById('contextmenu');
const main = document.getElementById("main");
main.addEventListener('contextmenu', (e) => {
e.preventDefault();
contextmenu.style.left = e.pageX + 'px';
contextmenu.style.top = e.pageY + 'px';
contextmenu.style.display = 'block';
});
main.addEventListener('click', () => {
contextmenu.style.display = 'none';
});

HTML

<div id="contextmenu">
<ul>
<li>Delete</li>
</ul>
</div>

CSS

#contextmenu {
display: none;
position: fixed;
left: 0;
top: 0;
border-radius: 8px;
background-color: #F9F9F9;
border: solid 1px #E3E3E3;
padding: 4px;
width: 192px;
}

#contextmenu ul{
padding-left: 0;
margin: 0;
}

#contextmenu li {
cursor: pointer;
margin: 0;
padding: 4.75px 0 4.75px 16px;
border-radius: 4px;
list-style: none;
font-size: 14px;
}

※ The event and functionality for when it is clicked will need to be created separately.

Installation Guide for rbenv (WSL2 / Ubuntu)

· One min read
ひかり
Main bloger

Installing Dependencies

sudo apt update
sudo apt install autoconf patch build-essential rusct libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev -y

Installing rbenv

# Install rbenv and ruby-build
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash

# Initialize rbenv on startup
echo 'eval "$($HOME/.rbenv/bin/rbenv init - bash)"' | tee -a ~/.bashrc

Reference

Installing Ruby 3.3.0

source ~/.bashrc    # Initialize rbenv (can also be done after re-logging into WSL)
rbenv install 3.3.0 # Install Ruby 3.3.0
rbenv global 3.3.0 # Set Ruby 3.3.0 as the default

Reference

plink

· One min read

Using SerialConsole with Windows Terminal and pliink

Writing a Serial Communication Program for Arduino

To test serial communication using Windows Terminal and pliink, we will write a serial communication program for Arduino.

void setup() {
Serial.begin(9600);
}

void loop() {
if(Serial.aavailable() <= 0) return;
char data = Serial.read();
if(data == '\r'){
Serial.print("\n");
}else{
Serial.print(data);
}
}

Serial Communication with Arduino using pliink

The following command executes a pliink command from Windows Terminal to perform serial communication with Arduino.

pliink -serial COM1 -sercfg 9600,8,1,N,N

Basic Information Database Summary

· 5 min read

Relational Model

Correspondence between Relational Model and Relational Database

| Relational Model | Relational Database | |:-:-:|:-:-:| | Relation | Table | | Attribute | Column | | Tuple | Row | | Domain | Data type. A set of values that an attribute can take. |

  • No order to attributes
  • Attribute names are unique within a relation
  • Attribute names must always be given names

(Basic Information Technology Engineer Examination, Spring 2016, Problem 26) (Basic Information Technology Engineer Examination, Spring 2019, Problem 26)

Relational Database, Relational Database (RDB)

A relational database represents data using two-dimensional tables.

(Basic Information Technology Engineer Examination, Autumn 2011, Problem 31)

Schema

A schema is a collection of data definitions, such as data properties, formats, and relationships with other data.

(Basic Information Technology Engineer Examination, Autumn 2014, Problem 26)

3-Layer Schema

A 3-layer schema consists of:

  • External schema: Visible to users
  • Conceptual schema: Visible to developers
  • Internal schema: Physical structure

The purpose of a 3-layer schema is to ensure that changes to the physical storage structure of data do not affect application programs.

(Basic Information Technology Engineer Examination, Spring 2015, Problem 26)

Database Management System (DBMS)

Software that manages databases.

| Function | Overview | |:-:-:|:-:-:| | Integrity Maintenance | Function to maintain data integrity through exclusive control, referential constraints, and table constraints | | Disaster Recovery | Function to recover from database failures using rollback, forward roll, checkpoints, and logs | | Confidentiality Protection | Function to prevent data tampering and leakage |

(Basic Information Technology Engineer Examination, Spring 2001, Problem 70)

E-R Diagram (Entity-Relationship Diagram)

An E-R diagram shows the relationships between entities. An entity is a real-world object.

(Basic Information Technology Engineer Examination, Spring 2016, Problem 38)

Table Design

Primary Key (PK)

A column that uniquely identifies a row in a table.

  • Uniqueness constraint
  • NOT NULL constraint
  • Not necessarily at the beginning
  • Can also be a composite key (combination of multiple columns)

(Basic Information Technology Engineer Examination, Autumn 2013, Problem 30)

Foreign Key (FK)

A column that references the primary key of another table.

  • Referential constraint (constraint to maintain referential integrity)

(Basic Information Technology Engineer Examination, Spring 2016, Problem 29)

A relation is the relationship between tables using primary and foreign keys.

Data Normalization

Eliminating data redundancy and inconsistencies when constructing a database.

(Basic Information Technology Engineer Examination, Spring 2015, Problem 67) (Basic Information Technology Engineer Examination, Autumn 2016, Problem 67) (Basic Information Technology Engineer Examination, Autumn 2018, Problem 61)

First Normal Form

  • Eliminate repeating items
  • Eliminate items that can be calculated

Second Normal Form

Move items that are uniquely determined by only a part of the primary key to a separate table.

  • Partial functional dependency: A relationship where an item is uniquely determined by only a part of the primary key.
  • Fully functional dependency: A relationship where an item is uniquely determined by the primary key.

Third Normal Form

Move items that are determined by other items besides the primary key to a separate table.

  • Transitive functional dependency: A relationship where an item is uniquely determined by items other than the primary key.

SQL

DDL, Data Definition Language

CREATE TABLE

Creates a table. Corresponds to the conceptual schema. Represents the physical table.

CREATE TABLE TableName(ColumnName1 Type1, ...);

CREATE VIEW

Defines a view. Corresponds to the external schema. Represents a virtual table.

DML, Data Manipulation Language

SELECT

Performs a query (request).

SELECT Column, ... FROM Table, ... WHERE Conditions
  • Projection Operation to retrieve columns.

To retrieve Col,

SELECT Col FROM Table
  • Selection Operation to retrieve rows.

To retrieve rows where Price is 100 or 120,

SELECT * FROM Table WHERE Price=100 OR Price=120
SELECT * FROM Table WHERE Price IN (100, 120)

To retrieve rows where Price is between 100 and 200,

SELECT * FROM Table WHERE Price >= 100 AND Price <= 200
SELECT * FROM Table WHERE BETWEEN 100 AND 200

To retrieve rows where Name ends with "田",

SELECT * FROM Table WHERE Name LIKE "%田"
  • %: Matches 0 or more characters
  • _: Matches 1 or more characters

Join

  • DISTINCT: Combines duplicate rows into one.

Sorting (ORDER BY)

Ascending (ASC)

SELECT ... FROM ... ORDER BY ColumnName ASC

ASC is optional.

Descending (DESC)

SELECT ... FROM ... ORDER BY ColumnName DESC

Aggregate Functions

| Function | Meaning | |:-:-:|:-:-:| | AVG | Average | | COUNT | Number of rows | | MIN | Minimum value | | MAX | Maximum value | | SUM | Sum |

Grouping (GROUP BY)

SELECT ... FROM ... GROUP BY ColumnName

Alias (AS)

SUM(ColumnName) AS GOUKEI

Group Conditions (HAVING)

GROUP BY ColumnName HAVING ...

Include Rows (IN)

... WHERE IN (SELECT ...)

Not included rows use NOT IN

Correlated Subquery (EXISTS)

True if it exists

... WHERE EXISTS (SELECT ...)

Database Utilization

Data Warehouse

A place to accumulate large amounts of data obtained through various business activities for decision support.

(Basic Information Technology Engineer Examination, Spring 2010, Problem 33)

Data Mining

A technique to discover useful information and relationships from vast amounts of data held by companies, such as customer and market data.

(Basic Information Technology Engineer Examination, Autumn 2015, Problem 38) (Basic Information Technology Engineer Examination, Spring 2020, Problem 64) (Basic Information Technology Engineer Examination, Spring 2020, Problem 29)

Big Data

  • Diverse data such as SNS, videos, images, and audio.
  • Massive data volume.
  • Data collected in real-time.

(Basic Information Technology Engineer Examination, Spring 2020, Problem 63)

Open Data

Government and private data that can be freely reused in principle.