# alinux-network

Part of **ALINUX**

# Alibaba Cloud Linux Networking CLI Reference

## Command Overview

| Command | Purpose | Syntax |
|--------|---------|--------|
| `nmcli connection` | Manage persistent network connections | `nmcli connection [action] [options]` |
| `nmcli device` | Manage active network devices | `nmcli device [action] [options]` |
| `nmcli monitor` | Monitor real-time network changes | `nmcli monitor` |
| `sysctl` | View or modify kernel network parameters | `sysctl [flags] [parameter=value]` |
| `smcr` | Monitor SMC-R (RDMA-based) statistics and links | `smcr [subcommand] [options]` |
| `smcss` | List and inspect active SMC connections | `smcss [options]` |
| `smc_monitor_ex` | Real-time SMC performance monitoring | `smc_monitor_ex [mode] [options]` |

## Command Details

### nmcli connection

**Purpose**: Manage persistent network connection profiles (e.g., Ethernet, VLAN) stored by NetworkManager.

**Syntax**:
```bash
nmcli connection [show|up|down|modify|add|delete] [connection-name] [options]
```

| Parameter | Short | Type | Required | Description |
|----------|-------|------|----------|-------------|
| `--fields` | `-f` | string | No | Specify which fields to display (e.g., `NAME,DEVICE`) |
| `+ipv4.addresses` | — | string | No | Add an IPv4 address (e.g., `192.0.2.10/24`) |
| `ipv4.addresses` | — | string | No | Replace all IPv4 addresses |
| `-ipv4.addresses` | — | string | No | Remove a specific IPv4 address |
| `802-3-ethernet.mtu` | — | integer | No | Set MTU value for Ethernet interface |
| `802-3-ethernet.cloned-mac-address` | — | string | No | Set custom MAC address |
| `+ipv4.routes` | — | string | No | Add a static route (e.g., `"198.51.100.0/24 192.0.2.1"`) |
| `ipv4.routes` | — | string | No | Replace all static routes |
| `-ipv4.routes` | — | string | No | Remove a specific route |
| `+ipv4.routing-rules` | — | string | No | Add a routing rule (e.g., `"priority 100 from 192.0.2.0/24 table 100"`) |
| `ipv4.routing-rules` | — | string | No | Replace all routing rules |
| `-ipv4.routing-rules` | — | string | No | Remove a specific routing rule |

```bash
# List all connections with key fields
nmcli -f NAME,FILENAME,TYPE,DEVICE connection

# Show details of a specific connection
nmcli connection show "System eth0"

# Bring a connection up
sudo nmcli connection up "System eth0"

# Set MTU to 9000
sudo nmcli connection modify "System eth0" 802-3-ethernet.mtu 9000

# Add an IP address
sudo nmcli connection modify "System eth0" +ipv4.addresses 192.0.2.10/24

# Add a static route
sudo nmcli connection modify "System eth0" +ipv4.routes "198.51.100.0/24 192.0.2.1"
```

### nmcli device

**Purpose**: Manage active network devices directly (temporary changes unless tied to a connection).

**Syntax**:
```bash
nmcli device [status|up|down|modify] [device-name] [options]
```

| Parameter | Short | Type | Required | Description |
|----------|-------|------|----------|-------------|
| `+ipv4.addresses` | — | string | No | Add an IPv4 address |
| `ipv4.addresses` | — | string | No | Replace all IPv4 addresses |
| `-ipv4.addresses` | — | string | No | Remove a specific IPv4 address |
| `802-3-ethernet.mtu` | — | integer | No | Set MTU |
| `+ipv4.routes` | — | string | No | Add a route |
| `+ipv4.routing-rules` | — | string | No | Add a routing rule |

```bash
# Show status of all devices
nmcli device status

# Bring a device up
sudo nmcli device up eth0

# Set MTU on device (temporary)
sudo nmcli device modify eth0 802-3-ethernet.mtu 1500
```

### sysctl

**Purpose**: View or modify kernel parameters, especially for TCP/IP stack tuning.

**Syntax**:
```bash
sysctl [ -w ] [parameter[=value] ... ]
```

| Parameter | Short | Type | Required | Description |
|----------|-------|------|----------|-------------|
| `-w` | — | flag | No | Write new values to parameters |
| `-p` | — | flag | No | Load settings from `/etc/sysctl.conf` |

```bash
# View current TCP TIME-WAIT timeout
sysctl net.ipv4.tcp_tw_timeout

# Set TCP TIME-WAIT timeout to 30 seconds
sudo sysctl -w net.ipv4.tcp_tw_timeout=30

# Persist change by writing to sysctl.conf
echo "net.ipv4.tcp_tw_timeout = 30" | sudo tee -a /etc/sysctl.conf

# Reload sysctl settings
sudo sysctl -p
```

**Output Example**:
```text
net.ipv4.tcp_tw_timeout = 30
```

### smcr

**Purpose**: Inspect SMC-R (RDMA-based Shared Memory Communication) statistics, link groups, and devices.

**Syntax**:
```bash
smcr [stats|linkgroup|device] [-d]
```

| Parameter | Short | Type | Required | Description |
|----------|-------|------|----------|-------------|
| `-d` | — | flag | No | Show detailed output for linkgroup |

```bash
# Show SMC-R connection statistics
smcr stats

# List link groups
smcr linkgroup

# Show detailed link group info
smcr -d linkgroup

# Show RDMA devices used by SMC
smcr device
```

**Output Example**:
```text
SMC-R Connections Summary
  Total connections handled          5076
  SMC connections                    5076
  Handshake errors                      0
  TCP fallback                          0

RX Stats
  Data transmitted (Bytes)      200705600 (200.7M)
  Buffer full                           0 (0.00%)
```

### smcss

**Purpose**: List active SMC connections with state, addresses, and performance metrics.

**Syntax**:
```bash
smcss [-l] [-R] [-a]
```

| Parameter | Short | Type | Required | Description |
|----------|-------|------|----------|-------------|
| `-l` | — | flag | No | Show local address information |
| `-R` | — | flag | No | Show receive/send rates |
| `-a` | — | flag | No | Show all connection details |

```bash
# List all SMC connections
smcss

# Show connections with rates
smcss -R

# Show full connection details
smcss -a
```

### smc_monitor_ex

**Purpose**: Real-time monitoring of SMC performance (connections, memory, speed).

**Syntax**:
```bash
smc_monitor_ex [speed|connection|memory|base] -m [smc|smcr|smcd] -i [interval]
```

| Parameter | Short | Type | Required | Description |
|----------|-------|------|----------|-------------|
| `-m` | — | string | No | Mode: `smc`, `smcr`, or `smcd` (default: `smc`) |
| `-i` | — | integer | No | Update interval in seconds (default: 1) |
| `-r` | — | flag | No | Display raw bytes/sec without unit conversion |

```bash
# Monitor SMC-R connection count every 2 seconds
smc_monitor_ex connection -m smcr -i 2

# Monitor memory buffer usage
smc_monitor_ex memory -m smcr -i 1

# Monitor data transfer speed
smc_monitor_ex speed -m smcr -i 1
```

## Common Scenarios

### Scenario 1: Configure a Static IP and Route on Boot
```bash
# Step 1: Identify the connection name
nmcli -f NAME,DEVICE connection

# Step 2: Set static IP (replace "System eth0" with your connection name)
sudo nmcli connection modify "System eth0" ipv4.addresses 192.0.2.50/24

# Step 3: Add a static route
sudo nmcli connection modify "System eth0" +ipv4.routes "198.51.100.0/24 192.0.2.1"

# Step 4: Apply changes
sudo nmcli connection down "System eth0" && sudo nmcli connection up "System eth0"
```

### Scenario 2: Tune TCP for High-Load Applications
```bash
# Step 1: Reduce TIME-WAIT timeout
sudo sysctl -w net.ipv4.tcp_tw_timeout=30

# Step 2: Make change persistent across reboots
echo "net.ipv4.tcp_tw_timeout = 30" | sudo tee -a /etc/sysctl.conf

# Step 3: Verify current value
sysctl net.ipv4.tcp_tw_timeout

# Step 4: Count active TIME-WAIT sockets (optional verification)
netstat -ant | grep TIME_WAIT | wc -l
```

### Scenario 3: Monitor SMC Health in Real Time
```bash
# Step 1: Install smc-tools (if not already installed)
sudo yum install -y smc-tools

# Step 2: Check overall SMC-R health
smcr stats

# Step 3: Monitor active connections with throughput
smc_monitor_ex speed -m smcr -i 1
```

## Environment Setup

### Installation
- `nmcli` is pre-installed on Alibaba Cloud Linux 3 as part of NetworkManager.
- `smc-tools` must be installed manually for SMC monitoring:
  ```bash
  sudo yum install -y smc-tools
  ```

### Configuration
- **NetworkManager**: No additional setup required. Use `nmcli` with `sudo` for modifications.
- **Kernel Parameters**: Changes via `sysctl -w` are temporary. For persistence, add entries to `/etc/sysctl.conf` and run `sudo sysctl -p`.
- **SMC Monitoring**: Requires Alibaba Cloud Linux 3 with SMC-R enabled in the kernel (enabled by default on compatible instances).

## FAQ

Q: How do I make network configuration changes persistent across reboots?
A: Use `nmcli connection modify` (not `device modify`) to update persistent connection profiles. Changes take effect after `nmcli connection up`.

Q: What is the difference between `nmcli connection` and `nmcli device`?
A: `connection` manages saved profiles (persistent), while `device` controls the live interface state (temporary unless linked to a connection).

Q: Why isn’t my `sysctl` change surviving a reboot?
A: You must add the parameter to `/etc/sysctl.conf` or a file in `/etc/sysctl.d/` and run `sysctl -p` to load it at boot.

Q: How can I verify SMC is being used instead of TCP?
A: Run `smcr stats` and check that "SMC connections" > 0 and "TCP fallback" = 0. Also, use `smcss` to see active SMC connections.

Q: Do I need special hardware to use SMC monitoring tools?
A: Yes. SMC-R requires RDMA-capable instances (e.g., Alibaba Cloud hfr7 or hfc7 series). The tools will show no data if SMC is not active.