Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu.Wang 2019-03-18 09:19:45 +08:00
commit 415e501adc
7 changed files with 319 additions and 304 deletions

View File

@ -1,28 +1,30 @@
[#]: collector: (lujun9972)
[#]: translator: (MjSeven)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-10627-1.html)
[#]: subject: (Emoji-Log: A new way to write Git commit messages)
[#]: via: (https://opensource.com/article/19/2/emoji-log-git-commit-messages)
[#]: author: (Ahmad Awais https://opensource.com/users/mrahmadawais)
Emoji-Log编写 Git 提交信息的新方法
======
使用 Emoji-Log 为你的提交添加上下文。
> 使用 Emoji-Log 为你的提交添加上下文。
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/emoji_tech_keyboard.jpg?itok=ncBNKZFl)
我是一名全职开源开发人员,我喜欢称自己为“开源者”。我从事开源软件工作已经超过十年,并[构建了数百个][1]开源软件应用程序。
我是一名全职开源开发人员,我喜欢称自己为“开源者”。我从事开源软件工作已经超过十年,并[构建了数以百计的][1]开源软件应用程序。
同时我也是不要重复自己 Don't Repeat YourselfDRY哲学的忠实粉丝并且相信编写更好的 Git 提交消息是 DRY 的一个重要组成部分。它们具有足够的上下文关联可以作为你开源软件的变更日志。我编写的众多工作流之一是 [Emoji-Log][2],它是一个简单易用的开源 Git 提交日志标准。它通过使用表情符号来创建更好的 Git 提交消息从而改善了开发人员的体验DX
同时我也是<ruby>避免重复工作<rt>Don't Repeat Yourself</rt></ruby>DRY哲学的忠实粉丝并且我相信编写更好的 Git 提交消息是 DRY 的一个重要组成部分。它们具有足够的上下文关联可以作为你开源软件的变更日志。我编写的众多工作流之一是 [Emoji-Log][2],它是一个简单易用的开源 Git 提交日志标准。它通过使用表情符号来创建更好的 Git 提交消息从而改善了开发人员的体验DX
我使用 Emoji-Log 构建了 [VSCode Tips & Tricks 仓库][3] 和我的 🦄 [紫色 VSCode 主题仓库][4],以及一个看起来很漂亮的[自动变更日志][5]。
### Emoji-Log 的哲学
我喜欢表情符号,我很喜欢它们。编程,代码,极客/书呆子,开源...所有这一切本质上都很枯燥,有时甚至很无聊。表情符号帮助我添加颜色和情感。想要将感受添加到 2D、平面和基于文本的代码世界并没有错。
我喜欢(很多)表情符号,我很喜欢它们。编程、代码、极客/书呆子、开源……所有这一切本质上都很枯燥,有时甚至很无聊。表情符号帮助我添加颜色和情感。想要将感受添加到这个 2D 的、平板的、基于文本的代码世界并没有错。
相比于[数百个表情符号][6],我学会了更好的办法是保持小类别和普遍性。以下是指导使用 Emoji-Log 编写提交信息的原则:
相比于[数百个表情符号][6],我学会的更好办法是让类别较小和普遍性。以下是指导使用 Emoji-Log 编写提交信息的原则:
1. **必要的**
* Git 提交信息是必要的。
@ -31,10 +33,10 @@ Emoji-Log编写 Git 提交信息的新方法
* 例如,使用 ✅ **Create** 而不是 ❌ **Creating**
2. **规则**
* 少数类别易于记忆。
* 不多也少
* 例如 **📦 NEW** , **👌 IMPROVE** , **🐛 FIX** , **📖 DOC** , **🚀 RELEASE**, **✅ TEST**
* 不多也
* 例如 **📦 NEW** **👌 IMPROVE** 、 **🐛 FIX** 、 **📖 DOC** 、 **🚀 RELEASE** 、 **✅ TEST**
3. **行为**
* 让 Git 基于你所采取的操作提交
* 让 Git 的提交基于你所采取的操作
* 使用像 [VSCode][7] 这样的编辑器来提交带有提交信息的正确文件。
### 编写提交信息
@ -63,7 +65,7 @@ Emoji-Log编写 Git 提交信息的新方法
### Emoji-Log 函数
为了快速构建原型,我写了以下函数,你可以将它们添加到 **.bashrc** 或者 **.zshrc** 文件中以快速使用 Emoji-Log。
为了快速构建原型,我写了以下函数,你可以将它们添加到 `.bashrc` 或者 `.zshrc` 文件中以快速使用 Emoji-Log。
```
#.# Better Git Logs.
@ -126,7 +128,8 @@ funcsave gdoc
funcsave gtst
```
如果你愿意,可以将这些别名直接粘贴到 **~/.gitconfig** 文件:
如果你愿意,可以将这些别名直接粘贴到 `~/.gitconfig` 文件:
```
# Git Commit, Add all and Push — in one step.
cap = "!f() { git add .; git commit -m \"$@\"; git push; }; f"
@ -145,6 +148,17 @@ doc = "!f() { git cap \"📖 DOC: $@\"; }; f"
tst = "!f() { git cap \"✅ TEST: $@\"; }; f"
```
### Emoji-Log 例子
这里列出了一些使用 Emoji-Log 的仓库:
- [Create-guten-block toolkit](https://github.com/ahmadawais/create-guten-block/commits/)
- [VSCode Shades of Purple theme](https://github.com/ahmadawais/shades-of-purple-vscode/commits/)
- [Ahmad Awais' GitHub repos](https://github.com/ahmadawais) (我的最新的仓库)
- [CaptainCore CLI](https://github.com/CaptainCore/captaincore-cli/commits/) WordPress 管理工具)
- [CaptainCore GUI](https://github.com/CaptainCore/captaincore-gui/commits/) WordPress 插件)
你呢?如果你的仓库使用 Emoji-Log请将这个 [Emoji-Log 徽章](https://on.ahmda.ws/rOMZ/c)放到你的 README 中,并给我发送一个[拉取请求](https://github.com/ahmadawais/Emoji-Log/pulls),以让我可以将你的仓库列在这里。
--------------------------------------------------------------------------------
@ -153,7 +167,7 @@ via: https://opensource.com/article/19/2/emoji-log-git-commit-messages
作者:[Ahmad Awais][a]
选题:[lujun9972][b]
译者:[MjSeven](https://github.com/MjSeven)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -1,86 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Linux security: Cmd provides visibility, control over user activity)
[#]: via: (https://www.networkworld.com/article/3342454/linux-security-cmd-provides-visibility-control-over-user-activity.html)
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
Linux security: Cmd provides visibility, control over user activity
======
![](https://images.techhive.com/images/article/2017/01/background-1900329_1920-100705659-large.jpg)
There's a new Linux security tool you should be aware of — Cmd (pronounced "see em dee") dramatically modifies the kind of control that can be exercised over Linux users. It reaches way beyond the traditional configuration of user privileges and takes an active role in monitoring and controlling the commands that users are able to run on Linux systems.
Provided by a company of the same name, Cmd focuses on cloud usage. Given the increasing number of applications being migrated into cloud environments that rely on Linux, gaps in the available tools make it difficult to adequately enforce required security. However, Cmd can also be used to manage and protect on-premises systems.
### How Cmd differs from traditional Linux security controls
The leaders at Cmd — Milun Tesovic and Jake King — say organizations cannot confidently predict or control user behavior until they understand how users work routinely and what is considered “normal.” They seek to provide a tool that will granularly control, monitor, and authenticate user activity.
Cmd monitors user activity by forming user activity profiles (characterizing the activities these users generally perform), noticing abnormalities in their online behavior (login times, commands used, user locations, etc.), and preventing and reporting certain activities (e.g., downloading or modifying files and running privileged commands) that suggest some kind of system compromise might be underway. The product's behaviors are configurable and changes can be made rapidly.
The kind of tools most of us are using today to detect threats, identify vulnerabilities, and control user privileges have taken us a long way, but we are still fighting the battle to keep our systems and data safe. Cmd brings us a lot closer to identifying the intentions of hostile users whether those users are people who have managed to break into accounts or represent insider threats.
![1 sources live sessions][1]
View live Linux sessions
### How does Cmd work?
In monitoring and managing user activity, Cmd:
* Collects information that profiles user activity
* Uses the baseline to determine what is considered normal
* Detects and proactively prevents threats using specific indicators
* Sends alerts to responsible people
![2 triggers][3]
Building custom policies in Cmd
Cmd goes beyond defining what sysadmins can control through traditional methods, such as configuring sudo privileges, providing much more granular and situation-specific controls.
Administrators can select escalation policies that can be managed separately from the user privilege controls managed by Linux sysadmins.
The Cmd agent provides real-time visibility (not after-the-fact log analysis) and can block actions, require additional authentication, or negotiate authorization as needed.
Also, Cmd supports custom rules based on geolocation if user locations are available. And new policies can be pushed to agents deployed on hosts within minutes.
![3 command blocked][4]
Building a trigger query in Cmd
### Funding news for Cmd
[Cmd][2] recently got a financial boost, having [completed of a $15 million round of funding][5] led by [GV][6] (formerly Google Ventures) with participation from Expa, Amplify Partners, and additional strategic investors. This brings the company's raised funding to $21.6 million and will help it continue to add new defensive capabilities to the product and grow its engineering teams.
In addition, the company appointed Karim Faris, general partner at GV, to its board of directors.
Join the Network World communities on [Facebook][7] and [LinkedIn][8] to comment on topics that are top of mind.
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3342454/linux-security-cmd-provides-visibility-control-over-user-activity.html
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
[b]: https://github.com/lujun9972
[1]: https://images.idgesg.net/images/article/2019/02/1-sources-live-sessions-100789431-large.jpg
[2]: https://cmd.com
[3]: https://images.idgesg.net/images/article/2019/02/2-triggers-100789432-large.jpg
[4]: https://images.idgesg.net/images/article/2019/02/3-command-blocked-100789433-large.jpg
[5]: https://www.linkedin.com/pulse/changing-cybersecurity-announcing-cmds-15-million-funding-jake-king/
[6]: https://www.gv.com/
[7]: https://www.facebook.com/NetworkWorld/
[8]: https://www.linkedin.com/company/network-world

View File

@ -1,202 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (FSSlc)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How To Find Available Network Interfaces On Linux)
[#]: via: (https://www.ostechnix.com/how-to-find-available-network-interfaces-on-linux/)
[#]: author: (SK https://www.ostechnix.com/author/sk/)
How To Find Available Network Interfaces On Linux
======
![](https://www.ostechnix.com/wp-content/uploads/2019/02/network-interface-720x340.jpeg)
One of the common task we do after installing a Linux system is network configuration. Of course, you can configure network interfaces during the installation time. But, some of you might prefer to do it after installation or change the existing settings. As you know already, you must first know how many interfaces are available on the system in-order to configure network settings from command line. This brief tutorial addresses all the possible ways to find available network interfaces on Linux and Unix operating systems.
### Find Available Network Interfaces On Linux
We can find the available network cards in couple ways.
**Method 1 Using ifconfig Command:**
The most commonly used method to find the network interface details is using **ifconfig** command. I believe some of Linux users might still use this.
```
$ ifconfig -a
```
Sample output:
```
enp5s0: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 24:b6:fd:37:8b:29 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 171420 bytes 303980988 (289.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 171420 bytes 303980988 (289.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp9s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.225.37 netmask 255.255.255.0 broadcast 192.168.225.255
inet6 2409:4072:6183:c604:c218:85ff:fe50:474f prefixlen 64 scopeid 0x0<global>
inet6 fe80::c218:85ff:fe50:474f prefixlen 64 scopeid 0x20<link>
ether c0:18:85:50:47:4f txqueuelen 1000 (Ethernet)
RX packets 564574 bytes 628671925 (599.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 299706 bytes 60535732 (57.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
As you see in the above output, I have two network interfaces namely **enp5s0** (on board wired ethernet adapter) and **wlp9s0** (wireless network adapter) on my Linux box. Here, **lo** is loopback interface, which is used to access all network services locally. It has an ip address of 127.0.0.1.
We can also use the same ifconfig command in many UNIX variants, for example **FreeBSD** , to list available network cards.
**Method 2 Using ip Command:**
The ifconfig command is deprecated in the latest Linux versions. So you can use **ip** command to display the network interfaces as shown below.
```
$ ip link show
```
Sample output:
```
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp5s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 24:b6:fd:37:8b:29 brd ff:ff:ff:ff:ff:ff
3: wlp9s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
link/ether c0:18:85:50:47:4f brd ff:ff:ff:ff:ff:ff
```
![](https://www.ostechnix.com/wp-content/uploads/2019/02/ip-command.png)
You can also use the following commands as well.
```
$ ip addr
$ ip -s link
```
Did you notice that these command also shows the connected state of the network interfaces? If you closely look at the above output, you will notice that my Ethernet card is not connected with network cable (see the word **“DOWN”** in the above output). And wireless network card is connected (See the word **“UP”** ). For more details, check our previous guide to [**find the connected state of network interfaces on Linux**][1].
These two commands (ifconfig and ip) are just enough to find the available network cards on your Linux systems.
However, there are few other methods available to list network interfaces on Linux. Here you go.
**Method 3:**
The Linux Kernel saves the network interface details inside **/sys/class/net** directory. You can verify the list of available interfaces by looking into this directory.
```
$ ls /sys/class/net
```
Output:
```
enp5s0 lo wlp9s0
```
**Method 4:**
In Linux operating systems, **/proc/net/dev** file contains statistics about network interfaces.
To view the available network cards, just view its contents using command:
```
$ cat /proc/net/dev
```
Output:
```
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
wlp9s0: 629189631 566078 0 0 0 0 0 0 60822472 300922 0 0 0 0 0 0
enp5s0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
lo: 303980988 171420 0 0 0 0 0 0 303980988 171420 0 0 0 0 0 0
```
**Method 5: Using netstat command**
The **netstat** command displays various details such as network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
```
$ netstat -i
```
**Sample output:**
```
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
lo 65536 171420 0 0 0 171420 0 0 0 LRU
wlp9s0 1500 565625 0 0 0 300543 0 0 0 BMRU
```
Please be mindful that netstat is obsolete. The Replacement for “netstat -i” is “ip -s link”. Also note that this method will list only the active interfaces, not all available interfaces.
**Method 6: Using nmcli command**
The nmcli is nmcli is a command-line tool for controlling NetworkManager and reporting network status. It is used to create, display, edit, delete, activate, and deactivate network connections and display network status.
If you have Linux system with Network Manager installed, you can list the available network interfaces using nmcli tool using the following commands:
```
$ nmcli device status
```
Or,
```
$ nmcli connection show
```
You know now how to find the available network interfaces on Linux. Next, check the following guides to know how to configure IP address on Linux.
[How To Configure Static IP Address In Linux And Unix][2]
[How To Configure IP Address In Ubuntu 18.04 LTS][3]
[How To Configure Static And Dynamic IP Address In Arch Linux][4]
[How To Assign Multiple IP Addresses To Single Network Card In Linux][5]
If you know any other quick ways to do it, please share them in the comment section below. I will check and update the guide with your inputs.
And, thats all. More good stuffs to come. Stay tuned!
Cheers!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/how-to-find-available-network-interfaces-on-linux/
作者:[SK][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/how-to-find-out-the-connected-state-of-a-network-cable-in-linux/
[2]: https://www.ostechnix.com/configure-static-ip-address-linux-unix/
[3]: https://www.ostechnix.com/how-to-configure-ip-address-in-ubuntu-18-04-lts/
[4]: https://www.ostechnix.com/configure-static-dynamic-ip-address-arch-linux/
[5]: https://www.ostechnix.com/how-to-assign-multiple-ip-addresses-to-single-network-card-in-linux/

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (sanfusu )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,87 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Linux security: Cmd provides visibility, control over user activity)
[#]: via: (https://www.networkworld.com/article/3342454/linux-security-cmd-provides-visibility-control-over-user-activity.html)
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
Linux 安全Cmd 提供可视化控制用户活动
======
![](https://images.techhive.com/images/article/2017/01/background-1900329_1920-100705659-large.jpg)
你应该知道一个新的 Linux 安全工具--Cmd读作 “see em dee”极大地改变了可以对 Linux 用户进行控制的类型。它远远超出了传统的用户权限配置,,并在监视和控制用户能够在 Linux 系统上运行的命令方面发挥积极作用。
它由同名公司开发Cmd 专注于云应用。鉴于越来越多的应用迁移到依赖于 Linux 的云环境中可用工具的缺口使得难以充分实施所需的安全性。而且Cmd 还可用于管理和保护本地系统。
### Cmd 与传统 Linux 安全控件的区别
Cmd 公司的领导 Milun Tesovic 和 Jake King 表示,组织无法自信地预测或控制用户行为,直到他们了解了用户日常如何工作以及什么认为是“正常”。他们寻求提供一种能够精细控制、监控和验证用户活动的工具。
Cmd 通过形成用户活动配置文件(表示这些用户通常进行的活动)监视用户活动,注意其在线行为的异常(登录时间、使用的命令、用户位置等),以及预防和报告某些意味着系统攻击的活动(例如,下载或修改文件和运行特权命令)。产品的行为是可配置的,可以快速进行更改。
我们大多数人如今用来检测威胁、识别漏洞和控制用户权限的工具已经花费了很长的时间但我们仍在努力保持系统和数据的安全。Cmd 让我们更能够确定恶意用户的意图,无论这些用户是设法侵入帐户还是代表内部威胁。
![1 sources live sessions][1]
查看实时 Linux 会话
### Cmd 如何工作?
在监视和管理用户活动时Cmd
* 收集描述用户活动的信息
  * 使用基线来确定什么是正常的
  * 使用特定指标检测并主动防止威胁
  * 向负责人发送警报
![2 triggers][3]
在 Cmd 中构建自定义策略
Cmd 扩展了系统管理员通过传统方法控制的内容,例如配置 sudo 权限,提供更精细和特定情境的控制。
管理员可以选择可以与 Linux 系统管理员管理的用户权限控制分开管理的升级策略。
Cmd 客户端提供实时可视化(不是事后日志分析),并且可以阻止操作,它需要额外的身份验证或根据需要协商授权。
此外如果存在用户位置Cmd 支持基于地理定位的自定义规则。并且可以在几分钟内将新策略推送到部署在主机上的客户端。
![3 command blocked][4]
在 Cmd 中构建触发器查询
### Cmd 的融资新闻
[Cmd][2] 最近完成了由 [GV][6] (前身为 Google Ventures领投Expa、Amplify Partners 和其他战略投资者跟投的 [1500 万美元的融资][5]。这使该公司的融资金额达到了 2160 万美元,这将帮助其继续为该产品增加新的防御能力并发展其工程师团队。
此外,该公司还任命 GV 的普通合伙人 Karim Faris 为董事会成员。
在 [Facebook][7] 和 [LinkedIn][8] 中加入 Network World 社区,评论顶部话题。
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3342454/linux-security-cmd-provides-visibility-control-over-user-activity.html
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
[b]: https://github.com/lujun9972
[1]: https://images.idgesg.net/images/article/2019/02/1-sources-live-sessions-100789431-large.jpg
[2]: https://cmd.com
[3]: https://images.idgesg.net/images/article/2019/02/2-triggers-100789432-large.jpg
[4]: https://images.idgesg.net/images/article/2019/02/3-command-blocked-100789433-large.jpg
[5]: https://www.linkedin.com/pulse/changing-cybersecurity-announcing-cmds-15-million-funding-jake-king/
[6]: https://www.gv.com/
[7]: https://www.facebook.com/NetworkWorld/
[8]: https://www.linkedin.com/company/network-world

View File

@ -0,0 +1,202 @@
[#]: collector: (lujun9972)
[#]: translator: (FSSlc)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How To Find Available Network Interfaces On Linux)
[#]: via: (https://www.ostechnix.com/how-to-find-available-network-interfaces-on-linux/)
[#]: author: (SK https://www.ostechnix.com/author/sk/)
如何在 Linux 中查看可用的网络接口
======
![](https://www.ostechnix.com/wp-content/uploads/2019/02/network-interface-720x340.jpeg)
在我们安装完一个 Linux 系统后最为常见的任务便是网络配置了。当然,你可以在安装系统时进行网络接口的配置。但是,对于某些人来说,他们更偏爱在安装完系统后再进行网络的配置或者更改现存的设置。众所周知,为了在命令行中进行网络设定的配置,我们首先必须知道系统中有多少个可用的网络接口。本次这个简单的指南将列出所有可能的方式来在 Linux 和 Unix 操作系统中找到可用的网络接口。
### 在 Linux 中找到可用的网络接口
我们可以使用下面的这些方法来找到可用的网络接口。
**方法 1 —— 使用 `ifconfig` 命令:**
使用 **`ifconfig`** 命令来查看网络接口仍然是最常使用的方法。我相信还有很多 Linux 用户仍然使用这个方法。
```
$ ifconfig -a
```
示例输出:
```
enp5s0: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 24:b6:fd:37:8b:29 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 171420 bytes 303980988 (289.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 171420 bytes 303980988 (289.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp9s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.225.37 netmask 255.255.255.0 broadcast 192.168.225.255
inet6 2409:4072:6183:c604:c218:85ff:fe50:474f prefixlen 64 scopeid 0x0<global>
inet6 fe80::c218:85ff:fe50:474f prefixlen 64 scopeid 0x20<link>
ether c0:18:85:50:47:4f txqueuelen 1000 (Ethernet)
RX packets 564574 bytes 628671925 (599.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 299706 bytes 60535732 (57.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
```
如上面的输出所示,在我的 Linux 机子上有两个网络接口,它们分别叫做 **enp5s0**(主板上的有线网卡)和 **wlp9s0**(无线网卡)。其中的 **lo** 是环回网卡,被用来访问本地的网络的服务,通常它的 IP 地址为 127.0.0.1。
我们也可以在许多 UNIX 变种例如 **FreeBSD** 中使用相同的 `ifconfig` 来列出可用的网卡。
**方法 2 —— 使用 `ip` 命令:**
在最新的 Linux 版本中, `ifconfig` 命令已经被弃用了。你可以使用 **`ip`** 命令来罗列出网络接口,正如下面这样:
```
$ ip link show
```
示例输出:
```
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp5s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 24:b6:fd:37:8b:29 brd ff:ff:ff:ff:ff:ff
3: wlp9s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
link/ether c0:18:85:50:47:4f brd ff:ff:ff:ff:ff:ff
```
![](https://www.ostechnix.com/wp-content/uploads/2019/02/ip-command.png)
你也可以使用下面的命令来查看。
```
$ ip addr
```
```
$ ip -s link
```
你注意到了吗?这些命令同时还显示出了已经连接的网络接口的状态。假如你仔细查看上面的输出,你将注意到我的有线网卡并没有跟网络线缆连接(从上面输出中的 **DOWN** 可以看出)。另外,我的无线网卡已经连接了(从上面输出中的 **UP** 可以看出)。想知晓更多的细节,可以查看我们先前的指南 [**在 Linux 中查看网络接口的已连接状态**][1]。
这两个命令ifconfig 和 ip已经足够在你的 LInux 系统中查看可用的网卡了。
然而,仍然有其他方法来列出 Linux 中的网络接口,下面我们接着看。
**方法 3**
Linux 内核将网络接口的详细信息保存在 **/sys/class/net** 目录中,你可以通过查看这个目录的内容来检验可用接口的列表是否和前面的结果相符。
```
$ ls /sys/class/net
```
示例输出:
```
enp5s0 lo wlp9s0
```
**方法 4**
在 Linux 操作系统中,文件 **/proc/net/dev** 中包含有关网络接口的信息。
要查看可用的网卡,只需使用下面的命令来查看上面文件的内容:
```
$ cat /proc/net/dev
```
示例输出:
```
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
wlp9s0: 629189631 566078 0 0 0 0 0 0 60822472 300922 0 0 0 0 0 0
enp5s0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
lo: 303980988 171420 0 0 0 0 0 0 303980988 171420 0 0 0 0 0 0
```
**方法 5 使用 `netstat` 命令*
**netstat** 命令可以列出各种不同的信息,例如网络连接、路由表、接口统计信息、伪装连接和多播成员等。
```
$ netstat -i
```
示例输出:
```
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
lo 65536 171420 0 0 0 171420 0 0 0 LRU
wlp9s0 1500 565625 0 0 0 300543 0 0 0 BMRU
```
请注意 `netstat` 被弃用了, `netstat -i` 的替代命令是 `ip -s link`。另外需要注意的是这个方法将只列出激活的接口,而不是所有可用的接口。
**方法 6 使用 `nmcli` 命令**
`nmcli` 是一个用来控制 `NetworkManager` 和报告网络状态的命令行工具。它可以被用来创建、展示、编辑、删除、激活、停用网络连接和展示网络状态。
假如你的 Linux 系统中安装了 `Network Manager`,你便可以使用下面的命令来使用 `nmcli` 列出可以的网络接口:
```
$ nmcli device status
```
或者
```
$ nmcli connection show
```
现在你知道了如何在 Linux 中找到可用网络接口的方法,接下来,请查看下面的指南来知晓如何在 Linux 中配置 IP 地址吧。
[如何在 Linux 和 Unix 中配置静态 IP 地址][2]
[如何在 Ubuntu 18.04 LTS 中配置 IP 地址][3]
[如何在 Arch Linux 中配置静态和动态 IP 地址][4]
[如何在 Linux 中为单个网卡分配多个 IP 地址][5]
假如你知道其他快捷的方法来在 Linux 中找到可用的网络接口,请在下面的评论部分中分享出来,我将检查你们的评论并更新这篇指南。
这就是全部的内容了,更多精彩内容即将呈现,请保持关注!
干杯!
--------------------------------------------------------------------------------
via: https://www.ostechnix.com/how-to-find-available-network-interfaces-on-linux/
作者:[SK][a]
选题:[lujun9972][b]
译者:[FSSlc](https://github.com/FSSlc)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.ostechnix.com/author/sk/
[b]: https://github.com/lujun9972
[1]: https://www.ostechnix.com/how-to-find-out-the-connected-state-of-a-network-cable-in-linux/
[2]: https://www.ostechnix.com/configure-static-ip-address-linux-unix/
[3]: https://www.ostechnix.com/how-to-configure-ip-address-in-ubuntu-18-04-lts/
[4]: https://www.ostechnix.com/configure-static-dynamic-ip-address-arch-linux/
[5]: https://www.ostechnix.com/how-to-assign-multiple-ip-addresses-to-single-network-card-in-linux/