> For the complete documentation index, see [llms.txt](https://anida-huang.gitbook.io/notes-network-simulation-and-analysis/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anida-huang.gitbook.io/notes-network-simulation-and-analysis/qi-zhong/20210315-iperf.md).

# 20210322 Bridge ( 一 )

## 課堂資料

{% embed url="<https://www.youtube.com/user/smallko2007/videos>" %}

## 課堂練習

```
cd mininet
```

```
mkdir mytest
```

```
cd mytest
```

### 4.py

![](/files/-MYZcZ7dt8aXAVhHK3RO)

```
gedit 4.py
```

{% hint style="info" %}
**4.py**

```
#!/usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink
 
if '__main__' == __name__:
  net = Mininet(link=TCLink)
  h1 = net.addHost('h1')
  h2 = net.addHost('h2')
  r1 = net.addHost('r1')
  r2 = net.addHost('r2')
  Link(h1, r1)
  Link(h2, r2)
  Link(r1, r2)
  net.build()
  h1.cmd("ifconfig h1-eth0 0")
  h1.cmd("ip addr add 192.168.1.1/24 brd + dev h1-eth0")
  h1.cmd("ip route add default via 192.168.1.254")
  h2.cmd("ifconfig h2-eth0 0")
  h2.cmd("ip addr add 192.168.2.1/24 brd + dev h2-eth0")
  h2.cmd("ip route add default via 192.168.2.254")
  r1.cmd("ifconfig r1-eth0 0")
  r1.cmd("ifconfig r1-eth1 0")
  r1.cmd("ip addr add 192.168.1.254/24 brd + dev r1-eth0")
  r1.cmd("ip addr add 10.0.0.1/24 brd + dev r1-eth1")
  r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
  r1.cmd("ip route add 192.168.2.0/24 via 10.0.0.2")
  r2.cmd("ifconfig r2-eth0 0")
  r2.cmd("ifconfig r2-eth1 0")
  r2.cmd("ip addr add 192.168.2.254/24 brd + dev r2-eth0")
  r2.cmd("ip addr add 10.0.0.2/24 brd + dev r2-eth1")
  r2.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
  r2.cmd("ip route add 192.168.1.0/24 via 10.0.0.1")
  CLI(net)
  net.stop()
```

{% endhint %}

![](/files/-MYE9bBGEQcBoi6LQ4hN)

```
python 4.py
```

```
xterm r1 r2 
```

![](/files/-MYE9v27OxWXH4iDYmoK)

{% tabs %}
{% tab title="r1" %}

```
ip ro sh
```

![](/files/-MYEADtsjJQhBPId7KuJ)
{% endtab %}
{% endtabs %}

```
exit
```

```
python 4.py
```

```
xterm h1 h2 
```

![](/files/-MYEB4rEJoPFdKHhowPV)

{% tabs %}
{% tab title="h1" %}

```
ping 192.168.2.1
```

![](/files/-MYEAzq5bMhV_4-BjcDq)
{% endtab %}
{% endtabs %}

```
exit
```

### 5.py

![](/files/-MYEKa2h3rP_xDOmCRvg)

```
gedit 5.py
```

{% hint style="info" %}
**5.py**

```
#!/usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink
 
if '__main__' == __name__:
  net = Mininet(link=TCLink)
  h1 = net.addHost('h1')
  h2 = net.addHost('h2')
  r1 = net.addHost('r1')
  r2 = net.addHost('r2')
  Link(h1, r1)
  Link(h2, r2)
  Link(r1, r2)
  net.build()
  h1.cmd("ifconfig h1-eth0 0")
  h1.cmd("ip addr add 192.168.1.1/24 brd + dev h1-eth0")
  h1.cmd("ip route add default via 192.168.1.254")
  h2.cmd("ifconfig h2-eth0 0")
  h2.cmd("ip addr add 22.1.1.1/24 brd + dev h2-eth0")
  h2.cmd("ip route add default via 22.1.1.254")
  r1.cmd("ifconfig r1-eth0 0")
  r1.cmd("ifconfig r1-eth1 0")
  r1.cmd("ip addr add 192.168.1.254/24 brd + dev r1-eth0")
  r1.cmd("ip addr add 12.1.1.1/24 brd + dev r1-eth1")
  r1.cmd("ip route add default via 12.1.1.2")
  r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
  r1.cmd("iptables -t nat -A POSTROUTING -o r1-eth1 -s 192.168.1.0/24 -j MASQUERADE")
  r2.cmd("ifconfig r2-eth0 0")
  r2.cmd("ifconfig r2-eth1 0")
  r2.cmd("ip addr add 22.1.1.254/24 brd + dev r2-eth0")
  r2.cmd("ip addr add 12.1.1.2/24 brd + dev r2-eth1")
  r2.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
  CLI(net)
  net.stop()
```

{% endhint %}

![](/files/-MYELgymUZA2utkXTmJa)

```
python 5.py
```

```
xterm h1 r1 r1
```

![](/files/-MYEOpOkzrnckXlC8QAF)

{% tabs %}
{% tab title="r1" %}

```
wireshark
```

![](/files/-MYEP2Ggfil_WF1qdI_O)
{% endtab %}

{% tab title="r1 - 2" %}

```
wireshark
```

![](/files/-MYEPAB2EvxS3q2AX0py)
{% endtab %}

{% tab title="h1" %}

```
 ping 22.1.1.2 -c 5
```

![](/files/-MYEOj4BEwUDWf-DBF_z)
{% endtab %}
{% endtabs %}

```
h1 ping h2 -c 5
```

![](/files/-MYEQIClAHmbJjGMyK2n)

{% tabs %}
{% tab title="h1" %}

```
ping 127.0.0.1 -c 5
```

```
ping 192.168.1.1 -c 5
```

```
ping 192.168.1.254 -c 5
```

```
ping 12.1.1.1 -c 5
```

![](/files/-MYERdoIm5unopFbVKOW)
{% endtab %}
{% endtabs %}

```
exit
```

```
cd ..
```

```
cd ..
```

### Bridge

![](/files/-MYOaKFMj3BI85rb5EoV)

```
mkdir test-mininet
```

```
cd test-mininet
```

```
mkdir bridge
```

```
cd bridge
```

![](/files/-MYEZeO49PgU9g8X2x97)

```
apt install bridge-utils
```

![](/files/-MYOWD2EA2RoqgQGyoKy)

```
gedit 1.py
```

{% hint style="info" %}
**1.py**

```
#! /usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink,Intf

if '__main__' == __name__:
  net = Mininet(link=TCLink)
  h1 = net.addHost('h1')
  h2 = net.addHost('h2')
  h3 = net.addHost('h3')
  br1 = net.addHost('br1')
  net.addLink(h1, br1)
  net.addLink(h2, br1)
  net.addLink(h3, br1)
  net.build()
  h1.cmd("ifconfig h1-eth0 0")
  h2.cmd("ifconfig h2-eth0 0")
  h3.cmd("ifconfig h3-eth0 0")
  br1.cmd("ifconfig br1-eth0 0")
  br1.cmd("ifconfig br1-eth1 0")
  br1.cmd("ifconfig br1-eth2 0")
  br1.cmd("brctl addbr mybr")
  br1.cmd("brctl addif mybr br1-eth0")
  br1.cmd("brctl addif mybr br1-eth1")
  br1.cmd("brctl addif mybr br1-eth2")
  br1.cmd("ifconfig mybr up")
  h1.cmd("ip address add 192.168.10.1/24 dev h1-eth0")
  h2.cmd("ip address add 192.168.10.2/24 dev h2-eth0")
  h3.cmd("ip address add 192.168.10.3/24 dev h3-eth0")
  CLI(net)
  net.stop()
```

{% endhint %}

![](/files/-MYEhfuSp7QUB3RxizlN)

```
python 1.py
```

```
h1 ping h2 -c 5
```

```
h1 ping h3 -c 5
```

![](/files/-MYOWUzrafOLa62_0GB5)

```
exit
```

```
python 1.py
```

```
xterm br1
```

{% tabs %}
{% tab title="br1" %}

```
ifconfig
```

![](/files/-MYOWyjbhjuXpVCs1W6S)

```
brctl addbr mybr
```

```
brctl show
```

```
brctl addif mybr br1-eth0
```

```
brctl show
```

```
brctl addif mybr br1-eth1
```

```
brctl addif mybr br1-eth2
```

```
brctl show
```

```
ifconfig -a
```

```
ifconfig mybr up
```

![](/files/-MYOYqs5Q5kuTLpVagdA)

```
ifconfig
```

![](/files/-MYOZ-yVc2KnAxvVWHaT)
{% endtab %}
{% endtabs %}

```
h1 ping h2 -c 5
```

```
h1 ping h3 -c 5
```

```
h2 ping h3 -c 5
```

![](/files/-MYOZI6Xu4Jq0aW2wjzF)

```
xterm h2
```

{% tabs %}
{% tab title="h2" %}

```
tcpdump -i h2-eth0
```

![](/files/-MYOZye2dS9FoXWWWUrj)
{% endtab %}
{% endtabs %}

```
h1 ping h3 -c 5
```

![](/files/-MYOZeba3SBUyYdmciyv)

```
exit
```

![](/files/-MYOcbLDVCFmR_ODrNwI)

```
gedit 2.py
```

{% hint style="info" %}
**2.py**

```
#! /usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink,Intf

if '__main__' == __name__:
  net = Mininet(link=TCLink)
  h1 = net.addHost('h1')
  h2 = net.addHost('h2')
  h3 = net.addHost('h3')
  h4 = net.addHost('h4')
  br1 = net.addHost('br1')
  net.addLink(h1, br1)
  net.addLink(h2, br1)
  net.addLink(h3, br1)
  net.addLink(h4, br1)
  net.build()
  h1.cmd("ifconfig h1-eth0 0")
  h2.cmd("ifconfig h2-eth0 0")
  h3.cmd("ifconfig h3-eth0 0")
  h3.cmd("ifconfig h4-eth0 0")
  br1.cmd("ifconfig br1-eth0 0")
  br1.cmd("ifconfig br1-eth1 0")
  br1.cmd("ifconfig br1-eth2 0")
  br1.cmd("ifconfig br1-eth3 0")
  br1.cmd("brctl addbr mybr1")
  br1.cmd("brctl addbr mybr2")
  br1.cmd("brctl addif mybr1 br1-eth0")
  br1.cmd("brctl addif mybr1 br1-eth1")
  br1.cmd("brctl addif mybr2 br1-eth2")
  br1.cmd("brctl addif mybr2 br1-eth3")
  br1.cmd("ifconfig mybr1 up")
  br1.cmd("ifconfig mybr2 up")
  h1.cmd("ip address add 192.168.10.1/24 dev h1-eth0")
  h2.cmd("ip address add 192.168.10.2/24 dev h2-eth0")
  h3.cmd("ip address add 192.168.20.1/24 dev h3-eth0")
  h4.cmd("ifconfig h4-eth0 192.168.20.2/4")
  CLI(net)
  net.stop()
```

{% endhint %}

![](/files/-MYOc07DOwUKjE_-WJN2)

```
python 2.py
```

```
br1 ifconfig
```

![](/files/-MYOeD1sdxYGlAWBi4Hc)

```
br1 brctl show
```

```
h1 ping h2 -c 5
```

```
h1 ping h3
```

```
h1 ping h4
```

```
h3 ping h4 -c 5
```

![](/files/-MYOeY8WeIMlvPAt3b-d)

```
exit
```

```
gedit 2.py
```

{% hint style="info" %}
**2.py**

```
#! /usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink,Intf

if '__main__' == __name__:
  net = Mininet(link=TCLink)
  h1 = net.addHost('h1')
  h2 = net.addHost('h2')
  h3 = net.addHost('h3')
  h4 = net.addHost('h4')
  br1 = net.addHost('br1')
  net.addLink(h1, br1)
  net.addLink(h2, br1)
  net.addLink(h3, br1)
  net.addLink(h4, br1)
  net.build()
  h1.cmd("ifconfig h1-eth0 0")
  h2.cmd("ifconfig h2-eth0 0")
  h3.cmd("ifconfig h3-eth0 0")
  h3.cmd("ifconfig h4-eth0 0")
  br1.cmd("ifconfig br1-eth0 0")
  br1.cmd("ifconfig br1-eth1 0")
  br1.cmd("ifconfig br1-eth2 0")
  br1.cmd("ifconfig br1-eth3 0")
  br1.cmd("brctl addbr mybr1")
  br1.cmd("brctl addbr mybr2")
  br1.cmd("brctl addif mybr1 br1-eth0")
  br1.cmd("brctl addif mybr1 br1-eth1")
  br1.cmd("brctl addif mybr2 br1-eth2")
  br1.cmd("brctl addif mybr2 br1-eth3")
  br1.cmd("ifconfig mybr1 up")
  br1.cmd("ifconfig mybr2 up")
  h1.cmd("ip address add 192.168.10.1/24 dev h1-eth0")
  h2.cmd("ip address add 192.168.10.2/24 dev h2-eth0")
  h3.cmd("ip address add 192.168.20.1/24 dev h3-eth0")
  h4.cmd("ip address add 192.168.20.2/24 dev h4-eth0")
  CLI(net)
  net.stop()
```

{% endhint %}

![](/files/-MYOdwvgKZ8FN-WNmrBK)

```
python 2.py
```

```
h1 ping h2 -c 5
```

```
h1 ping h3
```

```
h1 ping h4
```

```
h3 ping h4
```

```
h3 ifconfig
```

![](/files/-MYOfvVt44_bgUoGbRyG)

```
h4 ifconfig
```

```
h4 ifconfig h4-eth0 0
```

```
h4 ifconfig h4-eth0 192.168.20.2/24
```

```
h3 ping h4 -c 5
```

![](/files/-MYOgAvVeoYip3wZtMZE)

```
exit
```

![](/files/-MYOhYJYpeUGly3HSew1)

```
gedit 3.py
```

{% hint style="info" %}
**3.py**

```
#! /usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink,Intf

if '__main__' == __name__:
  net = Mininet(link=TCLink)
  h1 = net.addHost('h1')
  h2 = net.addHost('h2')
  h3 = net.addHost('h3')
  h4 = net.addHost('h4')
  br1 = net.addHost('br1')
  r1 = net.addHost('r1')
  net.addLink(h1, br1)
  net.addLink(h2, br1)
  net.addLink(h3, br1)
  net.addLink(h4, br1)
  net.addLink(br1,r1)
  net.addLink(br1,r1)
  net.build()
  h1.cmd("ifconfig h1-eth0 0")
  h2.cmd("ifconfig h2-eth0 0")
  h3.cmd("ifconfig h3-eth0 0")
  h4.cmd("ifconfig h4-eth0 0")
  br1.cmd("ifconfig br1-eth0 0")
  br1.cmd("ifconfig br1-eth1 0")
  br1.cmd("ifconfig br1-eth2 0")
  br1.cmd("ifconfig br1-eth3 0")
  br1.cmd("ifconfig br1-eth4 0")
  br1.cmd("ifconfig br1-eth5 0")
  br1.cmd("brctl addbr mybr1")
  br1.cmd("brctl addbr mybr2")
  br1.cmd("brctl addif mybr1 br1-eth0")
  br1.cmd("brctl addif mybr1 br1-eth1")
  br1.cmd("brctl addif mybr1 br1-eth4")
  br1.cmd("brctl addif mybr2 br1-eth2")
  br1.cmd("brctl addif mybr2 br1-eth3")
  br1.cmd("brctl addif mybr2 br1-eth5")
  br1.cmd("ifconfig mybr1 up")
  br1.cmd("ifconfig mybr2 up")
  r1.cmd('ifconfig r1-eth0 192.168.10.254 netmask 255.255.255.0')
  r1.cmd('ifconfig r1-eth1 192.168.20.254 netmask 255.255.255.0')
  r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
  h1.cmd("ip address add 192.168.10.1/24 dev h1-eth0")
  h1.cmd("ip route add default via 192.168.10.254")
  h2.cmd("ip address add 192.168.10.2/24 dev h2-eth0")
  h2.cmd("ip route add default via 192.168.10.254")
  h3.cmd("ip address add 192.168.20.1/24 dev h3-eth0")
  h3.cmd("ip route add default via 192.168.20.254")
  h4.cmd("ip address add 192.168.20.2/24 dev h4-eth0")
  h4.cmd("ip route add default via 192.168.20.254")
  CLI(net)
  net.stop()
```

{% endhint %}

![](/files/-MYOhp0OuOUFbQyTRtyj)

```
python 3.py
```

```
net
```

```
br1 brctl show
```

```
h1 ping h2 -c 5
```

```
h1 ping h3 -c 5
```

![](/files/-MYOiaClHX-cg6KxGV9w)

```
h1 ping h4 -c 5
```

```
exit
```

![](/files/-MYOilL6O6ioufsDQU01)

```
apt install vlan
```

![](/files/-MYOj1W2jwtr2zrPRjNr)

```
gedit 4.py
```

{% hint style="info" %}
**4.py**

```
#! /usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink,Intf

if '__main__' == __name__:
  net = Mininet(link=TCLink)
  h1 = net.addHost('h1')
  h2 = net.addHost('h2')
  h3 = net.addHost('h3')
  h4 = net.addHost('h4')
  br1 = net.addHost('br1')
  r1 = net.addHost('r1')
  net.addLink(h1, br1)
  net.addLink(h2, br1)
  net.addLink(h3, br1)
  net.addLink(h4, br1)
  net.addLink(br1,r1)
  net.build()
  h1.cmd("ifconfig h1-eth0 0")
  h2.cmd("ifconfig h2-eth0 0")
  h3.cmd("ifconfig h3-eth0 0")
  h4.cmd("ifconfig h4-eth0 0")
  r1.cmd("ifconfig r1-eth0 0")
  br1.cmd("ifconfig br1-eth0 0")
  br1.cmd("ifconfig br1-eth1 0")
  br1.cmd("ifconfig br1-eth2 0")
  br1.cmd("ifconfig br1-eth3 0")
  br1.cmd("ifconfig br1-eth4 0")
  br1.cmd("vconfig add br1-eth4 10")
  br1.cmd("vconfig add br1-eth4 20")
  r1.cmd("vconfig add r1-eth0 10")
  r1.cmd("vconfig add r1-eth0 20")
  br1.cmd("brctl addbr mybr10")
  br1.cmd("brctl addbr mybr20")
  br1.cmd("brctl addif mybr10 br1-eth0")
  br1.cmd("brctl addif mybr10 br1-eth1")
  br1.cmd("brctl addif mybr10 br1-eth4.10")
  br1.cmd("brctl addif mybr20 br1-eth2")
  br1.cmd("brctl addif mybr20 br1-eth3")
  br1.cmd("brctl addif mybr20 br1-eth4.20")
  br1.cmd("ifconfig br1-eth4.10 up")
  br1.cmd("ifconfig br1-eth4.20 up")
  r1.cmd("ifconfig r1-eth0.10 up")
  r1.cmd("ifconfig r1-eth0.20 up")
  br1.cmd("ifconfig mybr10 up")
  br1.cmd("ifconfig mybr20 up")
  r1.cmd('ifconfig r1-eth0.10 192.168.10.254 netmask 255.255.255.0')
  r1.cmd('ifconfig r1-eth0.20 192.168.20.254 netmask 255.255.255.0')
  r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
  h1.cmd("ip address add 192.168.10.1/24 dev h1-eth0")
  h1.cmd("ip route add default via 192.168.10.254")
  h2.cmd("ip address add 192.168.10.2/24 dev h2-eth0")
  h2.cmd("ip route add default via 192.168.10.254")
  h3.cmd("ip address add 192.168.20.1/24 dev h3-eth0")
  h3.cmd("ip route add default via 192.168.20.254")
  h4.cmd("ip address add 192.168.20.2/24 dev h4-eth0")
  h4.cmd("ip route add default via 192.168.20.254")
  CLI(net)
  net.stop()
```

{% endhint %}

![](/files/-MYOoO62bzFqAR8DCyV0)

```
python 4.py
```

```
xterm br1 r1
```

{% tabs %}
{% tab title="br1" %}

```
ifconfig
```

![](/files/-MYOprTLHMMBp8VXmZNN)
{% endtab %}

{% tab title="r1" %}

```
ifconfig
```

![](/files/-MYOpvkZRE5nYvAEOHF5)
{% endtab %}
{% endtabs %}

```
h1 ping h2 -c 5
```

```
h1 ping h3 -c 5
```

```
h1 ping h4 -c 5
```

![](/files/-MYOq8AbbwE0l59i5Dbg)

{% tabs %}
{% tab title="br1" %}

```
wireshark
```

![](/files/-MYOqN2M6KwWql2HzCmR)
{% endtab %}
{% endtabs %}

```
h1 ping h3 -c 5
```

![](/files/-MYOqf8PS7mwVubPqjbE)

```
exit
```

```
gedit test.py
```

{% hint style="info" %}
**test.py**

```
#! /usr/bin/env python
from mininet.cli import CLI
from mininet.net import Mininet
from mininet.link import Link,TCLink,Intf

if 'main' == name:
  net = Mininet(link=TCLink)
  h1 = net.addHost('h1')
  h2 = net.addHost('h2')
  h3 = net.addHost('h3')
  h4 = net.addHost('h4')
  br1 = net.addHost('br1')
  r1 = net.addHost('r1')
  net.addLink(h1, br1)
  net.addLink(h2, br1)
  net.addLink(h3, br1)
  net.addLink(h4, br1)
  net.addLink(br1,r1)
  net.build()
  h1.cmd("ifconfig h1-eth0 0")
  h2.cmd("ifconfig h2-eth0 0")
  h3.cmd("ifconfig h3-eth0 0")
  h4.cmd("ifconfig h4-eth0 0")
  r1.cmd("ifconfig r1-eth0 0")
  br1.cmd("ifconfig br1-eth0 0")
  br1.cmd("ifconfig br1-eth1 0")
  br1.cmd("ifconfig br1-eth2 0")
  br1.cmd("ifconfig br1-eth3 0")
  br1.cmd("ifconfig br1-eth4 0")
  br1.cmd("vconfig add br1-eth4 10")
  br1.cmd("vconfig add br1-eth4 20")
  r1.cmd("vconfig add r1-eth0 10")
  r1.cmd("vconfig add r1-eth0 20")
  br1.cmd("brctl addbr mybr10")
  br1.cmd("brctl addbr mybr20")
  br1.cmd("brctl addif mybr10 br1-eth0")
  br1.cmd("brctl addif mybr10 br1-eth1")
  br1.cmd("brctl addif mybr10 br1-eth4.10")
  br1.cmd("brctl addif mybr20 br1-eth2")
  br1.cmd("brctl addif mybr20 br1-eth3")
  br1.cmd("brctl addif mybr20 br1-eth4.20")
  br1.cmd("ifconfig br1-eth4.10 up")
  br1.cmd("ifconfig br1-eth4.20 up")
  r1.cmd("ifconfig r1-eth0.10 up")
  r1.cmd("ifconfig r1-eth0.20 up")
  br1.cmd("ifconfig mybr10 up")
  br1.cmd("ifconfig mybr20 up")
  r1.cmd('ifconfig r1-eth0.10 192.168.10.254 netmask 255.255.255.0')
  r1.cmd('ifconfig r1-eth0.20 192.168.20.254 netmask 255.255.255.0')
  r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")
  h1.cmd("ip address add 192.168.10.1/24 dev h1-eth0")
  h1.cmd("ip route add default via 192.168.10.254")
  h2.cmd("ip address add 192.168.10.2/24 dev h2-eth0")
  h2.cmd("ip route add default via 192.168.10.254")
  h3.cmd("ip address add 192.168.20.1/24 dev h3-eth0")
  h3.cmd("ip route add default via 192.168.20.254")
  h4.cmd("ip address add 192.168.20.2/24 dev h4-eth0")
  h4.cmd("ip route add default via 192.168.20.254")
  CLI(net)
  net.stop()
```

{% endhint %}

![](/files/-MYOresIgAdulBM0albf)

```
sed -i '/^$/d' test.py
```

* `將原來的所有空行刪除並在每一行後面增加一空行`
* `這樣在輸出的文本中每一行後面將有且只有一空行`

```
gedit test.py
```

![](/files/-MYOrz5bvdDEpMeqZYx8)

![](/files/-MYOsywTY3Co31N5EZY9)
