往 EdgeOS 系統裡面添加命令行
往 EdgeOS 系統裡面添加命令行
来源 https://help.tw.ui.com/articles/204976224/
概述
您可以向 EdgeOS 添加簡單的命令. 例如,reset 是頂層 EdgeOS 命令,在 CLI 中不可用.
步驟
列如,我們將添加一個命令來重置控制台.
1.首次運行復位命令時.
ubnt@RTR:~\$ reset ?openvpn
2.要添加命令,必須成為 root 用戶.sudo 命令用於獲取 root 用戶權限.
ubnt@RTR:~\$ sudo bash
root@RTR:/home/ubnt#
3.現在以 root 用戶身份,導航到具有所有操作模式模板的目錄.
root@RTR:/home/ubnt# cd /opt/vyatta/share/vyatta-op/templatesroot@RTR:/opt/vyatta/share/vyatta-op/templates# lsadd delete ping6 reset terminalclear disconnect reboot restart tracerouteconfigure generate release set traceroute6connect initial-setup remove show undebugcopy no rename shutdown updatedebug ping renew telnet
4.轉到復位目錄並創建復位子命令。
root@RTR:/opt/vyatta/share/vyatta-op/templates# cd resetroot@RTR:/opt/vyatta/share/vyatta-op/templates/reset# lsnode.def openvpn
5.使用 mkdir 命令創建一個名為 console 的目錄
root@RTR:/opt/vyatta/share/vyatta-op/templates/reset# mkdir consoleroot@RTR:/opt/vyatta/share/vyatta-op/templates/reset# cd console
6.在 root 中,使用 cat(concatenate)命令在控制台目錄中創建一個名為node.def的文件.添加行“幫助…”和“運行…”如下所列.點擊enter,然後按ctrl + c完成文件的編輯.
root@RTR:/opt/vyatta/share/vyatta-op/templates/reset/console# cat > node.defhelp: Reset the consolerun: /usr/bin/reset
7.退出 root 並嘗試新命令:
root@RTR:/opt/vyatta/share/vyatta-op/templates/reset/console# exitexitubnt@RTR:~$ reset ? console openvpn ubnt@RTR:~$ reset ?Possible completions: console Reset the console openvpn Reset OpenVPN
ubnt@RTR:~$ reset console
EdgeRouter - 怎麼通過腳本來更改配置模式?
来源 https://help.tw.ui.com/articles/115000120622/
答案
以下是一個使用腳本來改變隧道 IP 地址的例子:
ubnt@ubnt:~$ cat change_tun_ip
!/bin/vbash
if [ $# == 0 ]; then
echo usage: $0
exit 1
fi
new_ip=$1;
source /opt/vyatta/etc/functions/script-template
configure
set interfaces tunnel tun0 local-ip $new_ip
commit
save
exit
以下是另一個使用腳本來啟用/關閉一個 EdgeRouter 接口的 PoE:
!/bin/vbash
if [ $# -ne 2 ]; then
echo "usage: $0 [24v|48v|off]";
exit 1;
fi
intf=$1
val=$2
poe=/usr/sbin/ubnt-hal-e hasPoeE
if [ "$poe" != 1 ]; then
echo This platform does not support PoE;
exit 1;
fi
source /opt/vyatta/etc/functions/script-template
configure
set interfaces ethernet $intf poe output $val
commit
save
exit
在 Vyatta 的 CLI 腳本 API 頁面上還有一些可用的參考資訊
EdgeRouter - User Accounts
来源 https://help.ui.com/hc/en-us/articles/204976374
Default Username and Password
The default username and password combination for all EdgeRouter models is:
Username: ubnt
Password: ubnt
How to Add and Remove Users
1. Log in to the Web UI using the default user account.
Username: ubnt
Password: ubnt
2. Navigate to the Users tab and add a new user.
Users > Add User +
Username: <user>
Full Name: First and last name (optional)
Password: <secret>
Confirm: <secret>
Role: Admin
3. Log out of the system by clicking on the user account name in the top left on the Web UI.
4. Log in again using the newly created credentials.
5. Delete the default user account.
Users > ubnt > Actions > Delete
The above configuration can also be set using the CLI:
1. Log in to the CLI using the default user account.
Username: ubnt
Password: ubnt
2. Enter configuration mode.
configure
3. Add a new user and set the privilege level.
set system login user <user> authentication plaintext-password <secret>
set system login user <user> level admin
4. Commit the changes and save the configuration.
commit ; save
5. Log out of the system.
exit
6. Log in again using the newly created credentials.
7. Delete the default user account.
delete system login user ubnt
8. Commit the changes and save the configuration.
commit ; save
Configuring RADIUS Authentication
EdgeOS supports login authentication using a RADIUS server. Use the commands below to enable RADIUS authentication:
configure set system login radius-server <ip address> secret <radius key> commit save exit
EdgeRouter - Root User Account
来源 https://help.ui.com/hc/en-us/articles/204961724-EdgeRouter-Root-User-Account
Root User Privileges
The password on the root user account is not defined by default. This is a security precaution that prevents the root account from being used to log into the device (Web UI, CLI) using password-based authentication.
It is possible to access the root user shell to browse or modify the linux subsystem. Follow the steps below to elevate the prompt:
1. Log in using a previously created admin account.
2. Use the sudo command to elevate the privileges or invoke a root user shell.
ubnt@edgerouter:~$ sudo su
3. Use the exit command to return to the EdgeOS operational mode prompt.
root@edgerouter:/home/ubnt# exit
If necessary in your environment, follow the steps below to set the root user password.
1. Enter configuration mode.
configure
2. Set the root user account password.
set system login user root authentication plaintext-password <password>
3. Allow the root user to login via SSH.
set service ssh allow-root
4. Commit the changes and save the configuration.
commit ; save
Related Articles
EdgeRouter - Access the CLI from the Web UI
Intro to Networking - How to Establish a Connection Using SSH
配置为 2 层交换机
来源 https://help.ui.com.cn/articles/217990978/
使用向导自动配置交换机
最新的 EdgeOS 固件具有内置向导,可轻松将 EdgeRouter 配置为 2 层交换机,并具有 VLAN Aware 选项。
1.用网线从计算机连接到 EdgeRouter 上的 eth0 接口。
2.将计算机 IP 地址修改为 192.168.1.X/24 (X 不为 1,例如 192.168.1.11)。
3.打开 Web 浏览器,然后中输入 https://192.168.1.1。
4.使用默认账户密码据登录到路由器。
Username: ubnt
Password: ubnt
5.配置 switch0 接口和起 IP 地址。
6.打开 Wizards 选项卡,然后运行切换向导。
Wizards > Switch
7.设置路由器的管理访问设置。可用的选项有:
Management VLAN
(可选)设置用于管理流量的 VLAN ID。DHCP
使用此选项可通过 DHCP 接收地址。Static
使用此选项来配置静态 IP 地址。Username
默认设置为 ubnt。请您修改为其他账户密码。
8.将 EdgeRouter 配置为 VLAN Aware 模式。可用的选项有:
pvid
在交换机端口上 Untag 特定 VLAN。每个接口仅支持一个值。vid
交换端口上 tag 一个或多个 VLAN。每个接口支持多个值。
9.应用更改,并重启路由器。
下面展示了启用 VLAN Aware 模式并定义以下 VLAN 交换机端口设置:
eth0
untag VLAN10。eth1
Untag VLAN20。eth2
Untag VLAN30。eth3
Untag VLAN40。eth4
Untag VLAN10 tag VLAN20、30、40。eth5
Untag VLAN10 tag VLAN20、30、40。
**VLAN Aware:** Enabled
eth0: pvid 10
eth1: pvid 20
eth2: pvid 30
eth3: pvid 40
eth4: pvid 10
vid 20,30,40
eth5: pvid 10
vid 20,30,40
手动配置交换机功能
1.将网线从计算机连接到 EdgeRouter 上的 eth0 接口。
2.将计算机 IP 地址修改为 192.168.1.X/24 (X 不为 1,例如 192.168.1.11)。
3.打开 Web 浏览器,然后中输入 https://192.168.1.1。
4.使用默认账户密码据登录到路由器。
Username: ubnt
Password: ubnt
5.配置 switch0 接口和 IP 地址。
Dashboard > switch0 > Actions > Config
Address: Manually define IP address
IP: 192.168.2.1/24
6.将 switch0 接口与相关的交换机端口相关联,eth0 除外。
Dashboard > switch0 > Actions > VLAN
VLAN Aware: Unchecked
eth0: Unchecked
eth1: Checked
eth2: Checked
eth3: Checked
eth4: Checked
eth5: Checked
7.将计算机重新插入其他交换机接口之一。
8.将计算机上的静态 IP 更改为 192.168.2.X/24(X 不为 1 例如 192.168.2.11)。
9.打开 Web 浏览器,然后输入 https://192.168.2.1。
10.从 eth0 接口删除 IP 地址。
Dashboard > eth0 > Actions > Config
Address: No address
11.将 switch0 接口与 eth0 接口关联。
Dashboard > switch0 > Actions > VLAN
eth0: Checked
使用 CLI 命令配置 EdgeRouter 作为交换机使用
1.访问 EdgeRouter 的 CLI,配置 switch0 接口和 IP 地址
configure
set interfaces switch switch0 switch-port interface eth1
set interfaces switch switch0 switch-port interface eth2
set interfaces switch switch0 switch-port interface eth3
set interfaces switch switch0 switch-port interface eth4
set interfaces switch switch0 switch-port interface eth5
Set interfaces switch switch0 address 192.168.2.1/24
commit
save
exit
2.连接 switch0 并访问 CLI,移除 eth0 的 IP 地址并将 eth0 加入到 switch0
configure
delete interfaces ethernet eth0 address
commit
set interfaces switch switch0 switch-port interface eth0
commit
save
exit
3.开启 VLAN Aware,配置 eth0 作为 trunk 配置 vlan1 和 vlan9-11,eth1 配置 untag vlan9,eth2 配置 untag vlan10,eth3 配置 untag vlan11
configure
set interfaces switch switch0 switch-port vlan-aware enable
set interfaces switch switch0 switch-port interface eth0 vlan pvid 1
set interfaces switch switch0 switch-port interface eth0 vlan vid 9
set interfaces switch switch0 switch-port interface eth0 vlan vid 10
set interfaces switch switch0 switch-port interface eth0 vlan vid 11
set interfaces switch switch0 switch-port interface eth1 vlan pvid 9
set interfaces switch switch0 switch-port interface eth2 vlan pvid 10
set interfaces switch switch0 switch-port interface eth2 vlan pvid 11
commit
save
exit
=========== End
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
2022-01-23 xargs
2019-01-23 Win10 GodMode