VyOS python

19 篇文章 0 订阅

在 http://vyos.io/ 下载 

wget http://packages.vyos.net/iso/release/1.1.7/vyos-1.1.7-amd64.iso 


使用说明:

http://wiki.vyos.net/wiki/User_Guide


python-vyos:

https://github.com/vyos/python-vyos-mgmt


pip install --upgrade pip

pip install vymgmt


>>> import vymgmt
>>> 
>>> vyos = vymgmt.Router('192.168.23.131', 'vyos', password='qing123', port=22)
>>> 
>>> vyos.login()
>>> vyos.configure()
>>> vyos.set("protocols static route 203.0.113.0/25 next-hop 192.168.23.20")


vyos.set("protocols static route 203.0.113.0/25 next-hop 192.168.23.20")
vyos.set("interfaces ethernet eth0 address dhcp")
vyos.set("interfaces ethernet eth0 description 'OUTSIDE'")


vyos.set("service ssh port '22'")


vyos.set("system gateway-address 172.16.0.1")



vyos.set("interfaces ethernet eth1 address '192.168.0.1/24'")
vyos.set("interfaces ethernet eth1 description 'INSIDE'")


vyos.set("nat source rule 100 outbound-interface 'eth0'")
vyos.set("nat source rule 100 source address '192.168.0.0/24'")
vyos.set("nat source rule 100 translation address masquerade")


vyos.set("service dhcp-server disabled 'false'")
vyos.set("service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 default-router '192.168.0.1'")
vyos.set("service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 dns-server '192.168.0.1'")
vyos.set("service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 domain-name 'internal-network'")
vyos.set("service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 lease '86400'")
vyos.set("service dhcp-server shared-network-name LAN subnet 192.168.0.0/24 start 192.168.0.9 stop '192.168.0.254'")


vyos.set("service dns forwarding cache-size '0'")
vyos.set("service dns forwarding listen-on 'eth1'")
vyos.set("service dns forwarding name-server '8.8.8.8'")
vyos.set("service dns forwarding name-server '8.8.4.4'")


vyos.set("firewall name OUTSIDE-IN default-action 'drop'")
vyos.set("firewall name OUTSIDE-IN rule 10 action 'accept'")
vyos.set("firewall name OUTSIDE-IN rule 10 state established 'enable'")
vyos.set("firewall name OUTSIDE-IN rule 10 state related 'enable'")


vyos.set("firewall name OUTSIDE-LOCAL default-action 'drop'")
vyos.set("firewall name OUTSIDE-LOCAL rule 10 action 'accept'")
vyos.set("firewall name OUTSIDE-LOCAL rule 10 state established 'enable'")
vyos.set("firewall name OUTSIDE-LOCAL rule 10 state related 'enable'")
vyos.set("firewall name OUTSIDE-LOCAL rule 20 action 'accept'")
vyos.set("firewall name OUTSIDE-LOCAL rule 20 icmp type-name 'echo-request'")
vyos.set("firewall name OUTSIDE-LOCAL rule 20 protocol 'icmp'")
vyos.set("firewall name OUTSIDE-LOCAL rule 20 state new 'enable'")
vyos.set("firewall name OUTSIDE-LOCAL rule 30 action 'drop'")
vyos.set("firewall name OUTSIDE-LOCAL rule 30 destination port '22'")
vyos.set("firewall name OUTSIDE-LOCAL rule 30 protocol 'tcp'")
vyos.set("firewall name OUTSIDE-LOCAL rule 30 recent count '4'")
vyos.set("firewall name OUTSIDE-LOCAL rule 30 recent time '60'")
vyos.set("firewall name OUTSIDE-LOCAL rule 30 state new 'enable'")
vyos.set("firewall name OUTSIDE-LOCAL rule 31 action 'accept'")
vyos.set("firewall name OUTSIDE-LOCAL rule 31 destination port '22'")
vyos.set("firewall name OUTSIDE-LOCAL rule 31 protocol 'tcp'")
vyos.set("firewall name OUTSIDE-LOCAL rule 31 state new 'enable'")


vyos.set("interfaces ethernet eth0 firewall in name 'OUTSIDE-IN'")
vyos.set("interfaces ethernet eth0 firewall local name 'OUTSIDE-LOCAL'")

>>> vyos.run_op_mode_command('show vpn remote-access')
u' show vpn remote-access\r\n\x1b[?1h\x1b=\rActive remote access VPN sessions:\x1b[m\r\n\x1b[m\r\nUser            Proto Iface     Tunnel IP       TX byte RX byte  Time \x1b[m\r\n----            ----- -----     ---------       ------- -------  ---- \x1b[m\r\nroot            L2TP  l2tp0     192.168.255.1        74    4.4K  00h00m06s\x1b[m\r\n\r\x1b[K\x1b[?1l\x1b>'


>>> vyos.commit()
>>> vyos.save()
>>> vyos.exit()
>>> vyos.logout()


查看已配置命令

 show configuration commands



回滚

rollback <time>/<id>


推荐:https://github.com/abessifi/pyatta

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值