fedora下挂载lvm盘

挂载硬盘是linux下常用的一个操作。但是最近在挂载lvm盘的时候稍微遇见些小麻烦。使用lsblk命令显示硬盘信息如下:

loop0                            7:0    0    20K  1 loop /var/lib/snapd/snap/hello-world/29
loop1                            7:1    0  32.3M  1 loop /var/lib/snapd/snap/snapd/11588
loop2                            7:2    0  61.7M  1 loop /var/lib/snapd/snap/core20/975
loop3                            7:3    0  99.1M  1 loop /var/lib/snapd/snap/core/10958
sda                              8:0    0 931.5G  0 disk
├─sda1                           8:1    0   600M  0 part /boot/efi
├─sda2                           8:2    0     1G  0 part /boot
└─sda3                           8:3    0 929.9G  0 part /home
sdb                              8:16   0 931.5G  0 disk
├─sdb1                           8:17   0    10G  0 part
├─sdb2                           8:18   0     1G  0 part
├─sdb3                           8:19   0 911.5G  0 part
│ ├─fedora-home                253:1    0 775.5G  0 lvm  /home/super_stone
│ ├─fedora-root                253:2    0   120G  0 lvm
│ └─fedora-swap                253:3    0    16G  0 lvm
└─sdb4                           8:20   0     9G  0 part
  └─fedora_localhost--live-var 253:0    0     9G  0 lvm
sdc                              8:32   0 931.5G  0 disk
└─sdc1                           8:33   0 931.5G  0 part /opt/backup
zram0                          252:0    0     4G  0 disk [SWAP]

此时我们的目的是挂载sdb/sdb3下面的fedora-root硬盘。此时如果我们直接mount sdb3或者mount sdb3/fedora-root都会出现错误。正确的做法是通过fdisk -l查找到该虚拟盘的真实位置。我通过fdisk -l命令找到了fedora-root相关信息如下:

Disk /dev/mapper/fedora-root: 120.01 GiB, 128857407488 bytes, 251674624 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

于是,我执行如下命令成功挂载了该虚拟盘:

mount /dev/mapper/fedora-root /opt/old_disk

为fedora系统创建nfs服务器

nfs服务器可以作为kubernetes的存储空间系统的一部分来使用。我们可以参照下文为fedora系统创建一个nfs服务器:

sudo mkdir /srv/nfs/kubedata -p

sudo chown your_user /srv/nfs/kubedata/

sudo dnf install -y nfs-utils

sudo systemctl enable nfs-server

sudo systemctl start nfs-server

接着,我们需要编辑一下exports的配置文件

sudo vi /etc/exports

添加以下内容

/srv/nfs/kubedata *(rw,sync,no_subtree_check,no_root_squash,no_all_squash,insecure)

接下来,我们可以挂载网络文件测试一下

sudo mount -t nfs <your_ip_address>:/srv/nfs/kubedata /mnt

测试没有问题的话,可以卸载:

sudo umount /mnt

systemd和cgroup

systemd是一个软件套装,它是很多linux发行版本的init系统。在这些发行版本中,systemd是第一个启动的进程,pid为1。它负责管理linux系统上运行的服务。systemd的出现是为了给在linux系统上的服务能提供一个统一的接口。比如说我们的fedora系统中启动一个服务都是通过systemctl start xxxx.service的指令来调用,就是托systemd的福。

cgroup是systemd软件套装中的一个软件,它允许用户为一组进程创建资源的限制和隔离。(例如在fedora系统上chrome浏览器可以给每一个页面的worker运行时最多只能占多少内存做出限制,这就是托cgroup的福)

在容器化技术比较普遍的今天,cgroup也为容器应用提供服务。例如我们能够给docker的container设定资源占用量,就是托的cgroup的福。

需要注意的是,在k8s安装教程中尤其的指出,容器运行时可能采用与systemd不同的cgroup,而且这会导致在系统资源比较紧张的情况下发生错误。于是我们需要手动指定容器使用systemd的cgroup。(因为在默认情况下,容器例如docker采用的不是systemd的cgroup,而是cgroupfs)

linux系统建立dns映射

Understanding Name Service Switch in Linux

Before moving any further, you should understand a few things about another important file that is /etc/nsswitch.conf. It provides Name Service Switch functionality which controls the order in which services are queried for name service lookups.

The configuration is based on order; if files is before dns it means the system will query the /etc/hosts file before checking DNS for name service requests. But if DNS is before files then the domain lookup process will consult DNS first before any other appropriate services or files.

In this scenario, we want to query the “files” service. To check the order, type.

$ cat /etc/nsswitch.conf
OR
$ grep hosts /etc/nsswitch.conf
Check Name Service Switch
Check Name Service Switch

Configure DNS Locally Using /etc/hosts File in Linux

Now open the /etc/hosts file using your editor of choice as follows

$ sudo vi /etc/hosts

Then add the lines below to the end of the file as shown in the screen shot below.

192.168.56.1   ubuntu.tecmint.lan
192.168.56.10  centos.tecmint.lan

Next, test if everything is working well as expected, using the ping command from Host 1, you can ping Host 2 using it domain name like so.

$ ping -c 4 centos.tecmint.lan 
OR
$ ping -c 4 centos
Ping Domain Locally
Ping Domain Locally

samba 拷贝远程目录

主要参考了两个地方

https://superuser.com/questions/856617/how-do-i-recursively-download-a-directory-using-smbclient

http://technotize.blogspot.com/2011/12/copy-folder-with-ubuntu-smb-client.html


cd path_to_your_destination_directory  // 打开需要拷贝到的目标目录
smbclient remote_address  // 链接远程地址
cd dirctory_for_copy // 打开需要拷贝的目录
recurse
prompt OFF
mget *

fedora samba的连接

参照fedora配置samba正确地完成了配置以后,可以参照以下简短描述添加用户,连接服务器等。

创建用户

useradd samba_test_user

锁定用户(因为是samba用,因此不允许此用户通过其他方式登陆服务器)

passwd --lock samba_test_user

添加此用户为smb用户

smbpasswd -a samba_test_user

将此用户添加到读写分组

gpasswd --add samba_test_user public_readwrite或者是public_readonly

连接服务器

smbclient --user=samba_test_user //localhost/public

改为远程后,localhost需要修改为ip地址或者域名

登陆后,可以通过get,put来上传和下载文件。可以通过help get 类似的方式来查看值令的帮助。

fedora 配置samba

Sharing files with Fedora 32 using Samba is cross-platform, convenient, reliable, and performant.

What is ‘Samba’?

Samba is a high-quality implementation of Server Message Block protocol (SMB). Originally developed by Microsoft for connecting windows computers together via local-area-networks, it is now extensively used for internal network communications.

Apple used to maintain it’s own independent file sharing called “Apple Filing Protocol (AFP)“, however in recent times, it also has also switched to SMB.

In this guide we provide the minimal instructions to enable:

  • Public Folder Sharing (Both Read Only and Read Write)
  • User Home Folder Access
Note about this guide: The convention '~]$' for a local user command prompt, and '~]#' for a super user prompt will be used.

Public Sharing Folder

Having a shared public place where authenticated users on an internal network can access files, or even modify and change files if they are given permission, can be very convenient. This part of the guide walks through the process of setting up a shared folder, ready for sharing with Samba.

Please Note: This guide assumes the public sharing folder is on a Modern Linux Filesystem; other filesystems such as NTFS or FAT32 will not work. Samba uses POSIX Access Control Lists (ACLs).

For those who wish to learn more about Access Control Lists, please consider reading the documentation: "Red Hat Enterprise Linux 7: System Administrator's Guide: Chapter 5. Access Control Lists", as it likewise applies to Fedora 32.

In General, this is only an issue for anyone who wishes to share a drive or filesystem that was created outside of the normal Fedora Installation process. (such as a external hard drive).

It is possible for Samba to share filesystem paths that do not support POSIX ACLs, however this is out of the scope of this guide.

Create Folder

For this guide the /srv/public/ folder for sharing will be used.

The /srv/ directory contains site-specific data served by a Red Hat Enterprise Linux system. This directory gives users the location of data files for a particular service, such as FTP, WWW, or CVS. Data that only pertains to a specific user should go in the /home/ directory.

RED HAT ENTERPRISE LINUX 7, STORAGE ADMINISTRATION GUIDE: CHAPTER 2. FILE SYSTEM STRUCTURE AND MAINTENANCE: 2.1.1.8. THE /SRV/ DIRECTORY
Make the Folder (will provide an error if the folder already exists).
~]# mkdir --verbose /srv/public

Verify folder exists:
~]$ ls --directory /srv/public

Expected Output:
/srv/public

Set Filesystem Security Context

To have read and write access to the public folder the public_content_rw_t security context will be used for this guide. Those wanting read only may use: public_content_t.

Label files and directories that have been created with the public_content_rw_t type to share them with read and write permissions through vsftpd. Other services, such as Apache HTTP Server, Samba, and NFS, also have access to files labeled with this type. Remember that booleans for each service must be enabled before they can write to files labeled with this type.

RED HAT ENTERPRISE LINUX 7, SELINUX USER’S AND ADMINISTRATOR’S GUIDE: CHAPTER 16. FILE TRANSFER PROTOCOL: 16.1. TYPES: PUBLIC_CONTENT_RW_T

Add /srv/public as “public_content_rw_t” in the system’s local filesystem security context customization registry:

Add new security filesystem security context:
~]# semanage fcontext --add --type public_content_rw_t "/srv/public(/.*)?"

Verifiy new security filesystem security context:
~]# semanage fcontext --locallist --list

Expected Output: (should include)
/srv/public(/.*)? all files system_u:object_r:public_content_rw_t:s0

Now that the folder has been added to the local system’s filesystem security context registry; The restorecon command can be used to ‘restore’ the context to the folder:

Restore security context to the /srv/public folder:
$~]# restorecon -Rv /srv/public

Verify security context was correctly applied:
~]$ ls --directory --context /srv/public/

Expected Output:
unconfined_u:object_r:public_content_rw_t:s0 /srv/public/

User Permissions

Creating the Sharing Groups

To allow a user to either have read only, or read and write accesses to the public share folder create two new groups that govern these privileges: public_readonly and public_readwrite.

User accounts can be granted access to read only, or read and write by adding their account to the respective group (and allow login via Samba creating a smb password). This process is demonstrated in the section: “Test Public Sharing (localhost)”.

Create the public_readonly and public_readwrite groups:
~]# groupadd public_readonly
~]# groupadd public_readwrite

Verify successful creation of groups:
~]$ getent group public_readonly public_readwrite

Expected Output: (Note: x:1...: number will probability differ on your System)
public_readonly:x:1009:
public_readwrite:x:1010:

Set Permissions

Now set the appropriate user permissions to the public shared folder:

Set User and Group Permissions for Folder:
~]# chmod --verbose 2700 /srv/public
~]# setfacl -m group:public_readonly:r-x /srv/public
~]# setfacl -m default:group:public_readonly:r-x /srv/public
~]# setfacl -m group:public_readwrite:rwx /srv/public
~]# setfacl -m default:group:public_readwrite:rwx /srv/public

Verify user permissions have been correctly applied:
~]$ getfacl --absolute-names /srv/public

Expected Output:
file: /srv/public
owner: root
group: root
flags: -s-
user::rwx
group::---
group:public_readonly:r-x
group:public_readwrite:rwx
mask::rwx
other::---
default:user::rwx
default:group::---
default:group:public_readonly:r-x
default:group:public_readwrite:rwx
default:mask::rwx
default:other::---

Samba

Installation

~]# dnf install samba

Hostname (systemwide)

Samba will use the name of the computer when sharing files; it is good to set a hostname so that the computer can be found easily on the local network.

View Your Current Hostname:
~]$ hostnamectl status

If you wish to change your hostname to something more descriptive, use the command:

Modify your system's hostname (example):
~]# hostnamectl set-hostname "simple-samba-server"
For a more complete overview of the hostnamectl command, please read the previous Fedora Magazine Article: "How to set the hostname on Fedora".

Firewall

Configuring your firewall is a complex and involved task. This guide will just have the most minimal manipulation of the firewall to enable Samba to pass through.

For those who are interested in learning more about configuring firewalls; please consider reading the documentation: "Red Hat Enterprise Linux 8: Securing networks: Chapter 5. Using and configuring firewall", as it generally applies to Fedora 32 as well.
Allow Samba access through the firewall:
~]# firewall-cmd --add-service=samba --permanent
~]# firewall-cmd --reload

Verify Samba is included in your active firewall:
~]$ firewall-cmd --list-services

Output (should include):
samba

Configuration

Remove Default Configuration

The stock configuration that is included with Fedora 32 is not required for this simple guide. In particular it includes support for sharing printers with Samba.

For this guide make a backup of the default configuration and create a new configuration file from scratch.

Create a backup copy of the existing Samba Configuration:
~]# cp --verbose --no-clobber /etc/samba/smb.conf /etc/samba/smb.conf.fedora0

Empty the configuration file:
~]# > /etc/samba/smb.conf

Samba Configuration

Please Note: This configuration file does not contain any global definitions; the defaults provided by Samba are good for purposes of this guide.
Edit the Samba Configuration File with Vim:
~]# vim /etc/samba/smb.conf

Add the following to /etc/samba/smb.conf file:

# smb.conf - Samba Configuration File

# The name of the share is in square brackets [],
#   this will be shared as //hostname/sharename

# There are a three exceptions:
#   the [global] section;
#   the [homes] section, that is dynamically set to the username;
#   the [printers] section, same as [homes], but for printers.

# path: the physical filesystem path (or device)
# comment: a label on the share, seen on the network.
# read only: disable writing, defaults to true.

# For a full list of configuration options,
#   please read the manual: "man smb.conf".

[global] 
[public] 
path = /srv/public 
comment = Public Folder 
read only = No

Write Permission

By default Samba is not granted permission to modify any file of the system. Modify system’s security configuration to allow Samba to modify any filesystem path that has the security context of public_content_rw_t.

For convenience, Fedora has a built-in SELinux Boolean for this purpose called: smbd_anon_write, setting this to true will enable Samba to write in any filesystem path that has been set to the security context of public_content_rw_t.

For those who are wishing Samba only have a read-only access to their public sharing folder, they may choose skip this step and not set this boolean.

There are many more SELinux boolean that are available for Samba. For those who are interested, please read the documentation: "Red Hat Enterprise Linux 7: SELinux User's and Administrator's Guide: 15.3. Samba Booleans", it also apply to Fedora 32 without any adaptation.
Set SELinux Boolean allowing Samba to write to filesystem paths set with the security context public_content_rw_t:
~]# setsebool -P smbd_anon_write=1

Verify bool has been correctly set:
$ getsebool smbd_anon_write

Expected Output:
smbd_anon_write --> on

Samba Services

The Samba service is divided into two parts that we need to start.

Samba ‘smb’ Service

The Samba “Server Message Block” (SMB) services is for sharing files and printers over the local network.

Manual: “smbd – server to provide SMB/CIFS services to clients

Enable and Start Services

For those who are interested in learning more about configuring, enabling, disabling, and managing services, please consider studying the documentation: "Red Hat Enterprise Linux 7: System Administrator's Guide: 10.2. Managing System Services".
Enable and start smb and nmb services:
~]# systemctl enable smb.service
~]# systemctl start smb.service

Verify smb service:
~]# systemctl status smb.service

Test Public Sharing (localhost)

To demonstrate allowing and removing access to the public shared folder, create a new user called samba_test_user, this user will be granted permissions first to read the public folder, and then access to read and write the public folder.

The same process demonstrated here can be used to grant access to your public shared folder to other users of your computer.

The samba_test_user will be created as a locked user account, disallowing normal login to the computer.

Create 'samba_test_user', and lock the account.
~]# useradd samba_test_user
~]# passwd --lock samba_test_user

Set a Samba Password for this Test User (such as 'test'):
~]# smbpasswd -a samba_test_user

Test Read Only access to the Public Share:

Add samba_test_user to the public_readonly group:
~]# gpasswd --add samba_test_user public_readonly

Login to the local Samba Service (public folder):
~]$ smbclient --user=samba_test_user //localhost/public

First, the ls command should succeed,
Second, the mkdir command should not work,
and finally, exit:
smb: \> ls
smb: \> mkdir error
smb: \> exit

Remove samba_test_user from the public_readonly group:
gpasswd --delete samba_test_user public_readonly

Test Read and Write access to the Public Share:

Add samba_test_user to the public_readwrite group:
~]# gpasswd --add samba_test_user public_readwrite

Login to the local Samba Service (public folder):
~]$ smbclient --user=samba_test_user //localhost/public

First, the ls command should succeed,
Second, the mkdir command should work,
Third, the rmdir command should work,
and finally, exit:
smb: \> ls
smb: \> mkdir success
smb: \> rmdir success
smb: \> exit

Remove samba_test_user from the public_readwrite group:
~]# gpasswd --delete samba_test_user public_readwrite

After testing is completed, for security, disable the samba_test_user‘s ability to login in via samba.

Disable samba_test_user login via samba:
~]# smbpasswd -d samba_test_user

Home Folder Sharing

In this last section of the guide; Samba will be configured to share a user home folder.

For example: If the user bob has been registered with smbpasswd, bob’s home directory /home/bob, would become the share //server-name/bob.

This share will only be available for bob, and no other users.

This is a very convenient way of accessing your own local files; however naturally it carries at a security risk.

Setup Home Folder Sharing

Give Samba Permission for Public Folder Sharing

Set SELinux Boolean allowing Samba to read and write to home folders:
~]# setsebool -P samba_enable_home_dirs=1

Verify bool has been correctly set:
$ getsebool samba_enable_home_dirs

Expected Output:
samba_enable_home_dirs --> on

Add Home Sharing to the Samba Configuration

Append the following to the systems smb.conf file:

# The home folder dynamically links to the user home. 
# If 'bob' user uses Samba: 
# The homes section is used as the template for a new virtual share: 
# [homes] 
# ...   (various options) 
# A virtual section for 'bob' is made: 
# Share is modified: [homes] -> [bob] 
# Path is added: path = /home/bob 
# Any option within the [homes] section is appended. 
# [bob] 
#       path = /home/bob 
# ...   (copy of various options) 
# here is our share, 
# same as is included in the Fedora default configuration. 
[homes]         
    comment = Home Directories         
    valid users = %S, %D%w%S         
    browseable = No         
    read only = No         
    inherit acls = Yes 

Reload Samba Configuration

Tell Samba to reload it's configuration:
~]# smbcontrol all reload-config

Test Home Directory Sharing

Switch to samba_test_user and create a folder in it's home directory:
~]# su samba_test_user
samba_test_user:~]$ cd ~
samba_test_user:~]$ mkdir --verbose test_folder
samba_test_user:~]$ exit

Enable samba_test_user to login via Samba:
~]# smbpasswd -e samba_test_user

Login to the local Samba Service (samba_test_user home folder):
$ smbclient --user=samba_test_user //localhost/samba_test_user

Test (all commands should complete without error):
smb: \> ls
smb: \> ls test_folder
smb: \> rmdir test_folder
smb: \> mkdir home_success
smb: \> rmdir home_success
smb: \> exit

Disable samba_test_user from login in via Samba:
~]# smbpasswd -d samba_test_user

为linux系统添加/替换一块硬盘到指定位置

这里以挂载一块新硬盘替换掉之前的/var为例

  1. 首先需要连接硬件
  2. 将硬盘分区,格式化。fdisk指令和mkfs.ext4指令
  3. 将硬盘分区挂载到一个临时位置例如: /mnt/sdb1
  4. 拷贝/var 到/mnt/sdb1 "cp -apx /var/* /mnt/sdb1"
  5. 移开老的/var. mv /var /var.old
  6. mkdir /var
  7. 修改/etc/fstab文件,在里面添加如下一行
    /dev/sdb1 /var auto nosuid,nodev,nofail,x-gvfs-show 0 0

fedora无法启动gnome的急救方法

有时候因为各种操作失误,硬件调整等可能会导致gnome无法启动。而且又无法通过ctrl+alt+F2等进入tty2。此时还有一种急救方案,可以通过命令行进入系统,然后修正一些东西后,重启。

1.在grub界面,按“e”进入配置界面。

2. 接着,在以"linux"开头的那一行的后面,添加一个“3”。这里要注意的是,这一行可能会有"\"来escape换行,所以这个“3”要添加到真正的这一行的行末。还需要注意的是,“3”与这样一行最末尾的那个字符要添加空格。这是以runlevel 3启动系统。

3. 按下ctrl +x 启动系统

linux route table优先级解析

每一个linux系统都包含一个路由器,因此每一个linux系统中有一个路由表格。这个表格掌管着每一个ip数据包的流动方向。在linux系统中通常可以用route或者ip route命令查看这个表格。其实更确切的说,应该是这些表格。因为linux系统不仅仅包含一个路由表格。

参考文献这里

The routing table is used in order of most specific to least specific.

However on linux it's a bit more complicated than you might expect. Firstly there is more than one routing table, and when which routing table is used is dependent on a number of rules.

To get the full picture:

$ ip rule show
0: from all lookup local
32766: from all lookup main
32767: from all lookup default

$ ip route show table local
broadcast 127.0.0.0 dev lo proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
broadcast 192.168.0.0 dev eth0 proto kernel scope link src 192.168.1.27
local 192.168.1.27 dev eth0 proto kernel scope host src 192.168.1.27
broadcast 192.168.1.255 dev eth0 proto kernel scope link src 192.168.1.27

$ ip route show table main
default via 192.168.1.254 dev eth0
192.168.0.0/23 dev eth0 proto kernel scope link src 192.168.1.27

$ ip route show table default

$
The local table is the special routing table containing high priority control routes for local and broadcast addresses.

The main table is the normal routing table containing all non-policy routes. This is also the table you get to see if you simply execute ip route show (or ip ro for short). I recommend not using the old route command anymore, as it only shows the main table and its output format is somewhat archaic.

The table default is empty and reserved for post-processing if previous default rules did not select the packet.

本文第一个要探讨的问题是,判断ip数据包由路由器中的哪一行数据决定它的去向。简单的ip route show命令输出示例如下:

default dev ppp0 proto static scope link metric 50
default via 192.168.3.1 dev enp0s31f6 proto dhcp metric 100
10.0.0.1 dev ppp0 proto kernel scope link src 10.0.0.100 metric 50
47.104.27.239 via 192.168.3.1 dev enp0s31f6 src 192.168.3.4
47.104.27.239 via 192.168.3.1 dev enp0s31f6 proto static metric 100
172.16.207.0/24 dev vmnet8 proto kernel scope link src 172.16.207.1
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
172.18.0.0/16 dev docker_gwbridge proto kernel scope link src 172.18.0.1
172.19.0.0/16 dev br-b2c2e76a9910 proto kernel scope link src 172.19.0.1 linkdown
172.22.0.0/16 dev br-669aebd3aa2f proto kernel scope link src 172.22.0.1
192.168.3.0/24 dev enp0s31f6 proto kernel scope link src 192.168.3.4 metric 100
192.168.3.1 dev enp0s31f6 proto static scope link metric 100
192.168.93.0/24 dev vmnet1 proto kernel scope link src 192.168.93.1
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown

我们假设有一个ip数据包的目标地址为172.17.4.10,如果单独看目标地址的话如下3行都满足它的去处:

default dev ppp0 proto static scope link metric 50
default via 192.168.3.1 dev enp0s31f6 proto dhcp metric 100

172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown

这里有一个首要原则,那就是ip数据包会发往route table中最具体的那个目的地。以上3行,中的1,2行的目标ip非常不具体,它满足所有ip地址。而第3行满足172.17.0.0 ~ 172.17.255.255这之间的所有ip,范围更狭窄。因此,系统判断第3行的规则更加具体。linux中的路由器将会采用第3行的记录来发送该ip数据包。

接下来我们讨论更复杂的问题,如果ip数据包的目标地址为182.0.9.1。此时在路由表格中满足此目标ip地址的有如下两行:

default dev ppp0 proto static scope link metric 50
default via 192.168.3.1 dev enp0s31f6 proto dhcp metric 100

在这种情况下,系统将遵守metric越小越优先的原则。metric越小表示更容易到达目的地。因此在这种情况下,系统会按照第一条信息投送ip数据包。

此处参考这里

what if you have two interfaces on the same IP space? – MikeSchem Jul 26 '18 at 20:25
@MikeSchem: Then the 'metric' parameter of both routes is used. (The OS will usually refuse to add two routes with identical prefix, identical prefixlen, and identical metric, or possibly merge them into an ECMP load-balanced route.) – user1686 Jul 26 '18 at 20:34