Skip to content

Instantly share code, notes, and snippets.

@jfqd
Created February 26, 2012 16:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jfqd/1917520 to your computer and use it in GitHub Desktop.
Save jfqd/1917520 to your computer and use it in GitHub Desktop.
Crossbow - Network in a Box - Samples build for OpenIndiana 151a
#!/bin/bash
# create a virtual switch
dladm create-etherstub vswitch0
# create a virtual nic connected to a physical nic
dladm create-vnic -l e1000g0 vnic_ext0 # dns
# create virtual nics connected to a virtual switch
dladm create-vnic -l vswitch0 vnic_int0 # dns
dladm create-vnic -l vswitch0 vnic_int1 # db
dladm create-vnic -l vswitch0 vnic_int2 # web
dladm create-vnic -l vswitch0 vnic_int3 # global
#!/bin/bash
ifconfig vnic_int3 plumb
ifconfig vnic_int3 inet 10.200.20.10/24
ifconfig vnic_int3 inet up
cat <<EOF > "/etc/hostname.vnic_int3"
10.200.20.10 netmask 255.255.255.0 broadcast + up
EOF
route add default 10.200.20.1
cat <<EOF > "/etc/defaultrouter"
10.200.20.1
EOF
#!/bin/bash
zfs create rpool/zones
zfs set mountpoint=/export/zones rpool/zones
chmod 0700 /export/zones
cat <<EOF > "/tmp/zone_template"
create -b
set zonepath=/export/zones/template
set ip-type=exclusive
set autoboot=false
commit
EOF
zonecfg -z template -f /tmp/zone_template
zoneadm -z template install
#!/bin/bash
cat <<EOF > "/tmp/zone_dns"
create -b
set zonepath=/export/zones/dns
set ip-type=exclusive
set autoboot=true
add net
set physical=vnic_ext0
end
add net
set physical=vnic_int0
end
commit
EOF
cat <<EOF > "/tmp/zone_dns_sysidcfg"
name_service=none
network_interface=vnic_ext0 {
primary
hostname=dns
ip_address=10.200.10.10
netmask=255.255.255.0
protocol_ipv6=no
default_route=10.200.10.1}
network_interface=vnic_int0 {
hostname=dns-int
ip_address=10.200.20.1
netmask=255.255.255.0
protocol_ipv6=no
default_route=NONE}
root_password=COh2GoD2MvK9Y
security_policy=none
terminal=vt100
timezone=Europe/Berlin
timeserver=localhost
nfs4_domain=dynamic
EOF
zonecfg -z dns -f /tmp/zone_dns
zoneadm -z dns clone template
cp /tmp/zone_dns_sysidcfg /export/zones/dns/root/etc/sysidcfg
zoneadm -z dns boot
cat <<EOF > "/export/zones/dns/root/tmp/dns-zone-setup"
echo "map vphys_ext0 10.200.20.0/24 -> 0/32 portmap tcp/udp auto" > /etc/ipf/ipnat.conf
echo "map vphys_ext0 10.200.20.0/24 -> 0/32" >> /etc/ipf/ipnat.conf
svcadm enable ipfilter
svcadm enable ipv4-forwarding
echo "nameserver 8.8.8.8" > /etc/resolv.conf
cp /etc/nsswitch.dns /etc/nsswitch.conf
EOF
zlogin dns "bash -c /tmp/dns-zone-setup"
#!/bin/bash
cat <<EOF > "/tmp/zone_db"
create -b
set zonepath=/export/zones/db
set ip-type=exclusive
set autoboot=true
add net
set physical=vnic_int1
end
commit
EOF
cat <<EOF > "/tmp/zone_db_sysidcfg"
name_service=none
network_interface=primary {
hostname=db
ip_address=10.200.20.11
netmask=255.255.255.0
protocol_ipv6=no
default_route=10.200.20.1}
root_password=COh2GoD2MvK9Y
security_policy=none
terminal=vt100
timezone=Europe/Berlin
timeserver=localhost
nfs4_domain=dynamic
EOF
zonecfg -z db -f /tmp/zone_db
zoneadm -z db clone template
cp /tmp/zone_db_sysidcfg /export/zones/db/root/etc/sysidcfg
zoneadm -z db boot
#!/bin/bash
cat <<EOF > "/tmp/zone_web"
create -b
set zonepath=/export/zones/web
set ip-type=exclusive
set autoboot=true
add net
set physical=vnic_int2
end
commit
EOF
cat <<EOF > "/tmp/zone_web_sysidcfg"
name_service=none
network_interface=primary {
hostname=web
ip_address=10.200.20.12
netmask=255.255.255.0
protocol_ipv6=no
default_route=10.200.20.1}
root_password=COh2GoD2MvK9Y
security_policy=none
terminal=vt100
timezone=Europe/Berlin
timeserver=localhost
nfs4_domain=dynamic
EOF
zonecfg -z web -f /tmp/zone_web
zoneadm -z web clone template
cp /tmp/zone_web_sysidcfg /export/zones/web/root/etc/sysidcfg
zoneadm -z web boot
#!/bin/bash
flowadm add-flow -l vnic_ext0 -a transport=TCP,local_port=80 http
flowadm add-flow -l vnic_ext0 -a transport=UDP,local_port=53 dns
flowadm add-flow -l vnic_ext0 -a transport=UDP,local_port=4729 vpn
dladm set-linkprop -p maxbw=100M vnic_ext0
dladm show-linkprop -p maxbw vnic_ext0
flowadm set-flowprop -p maxbw=40M http
flowadm set-flowprop -p maxbw=30M dns
flowadm set-flowprop -p maxbw=30M vpn
flowadm show-flow
flowadm show-flowprop
#!/bin/bash
dd if=/dev/zero of=testfile_100MB.bin bs=104857600 count=1
flowadm add-flow -l vnic_int2 -a transport=TCP,local_port=22 ssh
flowadm set-flowprop -p maxbw=100M ssh
time scp testfile_100MB.bin 10.200.20.12:testfile_100MB.bin
flowadm set-flowprop -p maxbw=50M ssh
time scp testfile_100MB.bin 10.200.20.12:testfile_100MB.bin
flowadm set-flowprop -p maxbw=30M ssh
time scp testfile_100MB.bin 10.200.20.12:testfile_100MB.bin
flowadm reset-flowprop ssh
flowadm remove-flow -l vnic_int2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment