openwrt软路由

Openwrt Soft Router

Posted by alovn on June 6, 2021

OpenWRT是一个高度模块化的嵌入式的Linux发行版,它拥有强大的网络组件和扩展性,常常被用于工控设备、智能家居、路由器等设备中。可以将它刷入固件作为路由器,也可以将它安装到虚拟机作为软路由。

今天由于意外断电导致ESXI重启了一次,之前用的routeros软路由读取磁盘失败而不能启动,短时间内不能马上处理好,便尝试用openwrt作为备用软路由方案。routeros比openwrt功能更全,而openwrt则更灵活,可以更好的实现定制化。

下载镜像

首先从官网下载镜像:

https://downloads.openwrt.org/releases/19.07.7/targets/x86/64/openwrt-19.07.7-x86-64-combined-ext4.img.gz

或者使用国内镜像:

https://mirror.sjtu.edu.cn/openwrt/releases/19.07.7/targets/x86/64/openwrt-19.07.7-x86-64-combined-ext4.img.gz

转换镜像

直接下载的格式ESXI或VMWare不能直接使用,需要先进行格式转换:

1
2
3
4
//解压
gzip -d openwrt-19.07.7-x86-64-combined-ext4.img.gz
//格式转换
qemu-img convert -f raw openwrt-19.07.7-x86-64-combined-ext4.img -O vmdk openwrt-19.07.7-x86-64-combined-ext4.vmdk

然后ESXI创建虚拟机时Virtual Disk Type 要选择 IDE,不然启动时会找不到分区!!

设置网络

openwrt启动后,由于没有设置网络还不能直接访问。进入虚拟机修改 /etc/config/network文件:

1
2
3
4
5
6
7
config interface 'lan'
    ption ifname 'eth0'
    option proto 'static'
    option ipaddr '192.168.18.200'
    option netmask '255.255.255.0'
    option gateway '192.168.18.1'
    list dns '192.168.18.1'

执行以下命令,重启网络。

1
/etc/init.d/network restart 

然后就可以打开浏览器, 输入IP,访问openwrt web管理界面了,初次进入是没有密码的,需要设置密码:

1
进入Openwrt Web管理 -> System -> Administration

允许wan口访问

需要注意 openwrt 默认只能使用lan口进行ssh或访问web管理界面,如果要使用wan口进行连接,需要修改防火墙设置:

1
进入Openwrt Web管理 -> Network -> Firewall -> General Settings -> Zone

将 wan=>转发的[入站数据]为accept(接受)。

安装软件

openwrt中使用opkg命令可以安装你需要的软件:

1
2
opkg update
opkg install curl

官方文档

遇到其它问题可以参考官方文档:https://openwrt.org/zh/packages/start