2015年11月5日木曜日

make a real machine from qemu image (仮想環境で作ったopenbsdを実環境で動かす)


i am greatly helped by openbsd fellows , especially 
tar over ssh   (thanks to Benny Lofgren)ん下
and 
install boot      (thanks to Jan Vlach).


(referrence 1) about qemu
    http://qemuandopenbsd.blogspot.jp/2015/09/qemu.html


in Japanese
夢(kvm)の中ではうまくいった。 じゃあこれを現実のハードデスクで 具現化したいとおもわないだろうか。
でも 霊界と現世との間では cpは通じない。
ただ sshという霊界トンネルをとおれば いけるのだ。
そのため tar over ssh を使う。
ただし 夢を見ながら 夢をコピーするので変質がおこる恐れもなきにしもあらずだ。

linuxの場合は うまい具合に qemu-nbdがあり、 これを使えば 夢からさめた後で コピーするので変質はおこらない。 同じのが openbsdにもあればなあと嘆く。 devつくてね


概略はこうだ 。
まず arch linuxをたちあげ 、
それから kvm guestとしてopenbsd.qcow2をたちあげる。
そして make world (正確には follow current)をする。
そしたら、openbsd.qcow2ができる。
linuxは openbsdのファイルシステムを認識できないので 、
一旦 linuxからもopenbsdからも読み書き可能なext2へコピーする。
次はopenbsdを立ち上げ ext2 から例えば /home/user-fogeへ openbsd.qcow2を コピーし、
これをopenbsd の qemu guestとして立ち上げる。
openbsdなので 他のドライブのopenbsdファイルシステムは認識するので
この他のドライブへ tar over sshで 写す。
これで終了だ!





i prepare 4 story .
i pactice and scceed  
            1st and 2nd and 3rd  story .


i have not practice   4th story yet .
but i guess it is perhaps OK .
 


1st story -----------------------
first overall view

 



i intend to install  [i386 openbsd] on the sd0a area.
i write this story .



1) on rental server

                       rental server (openbsd) is running at sd1a

mount /dev/sd0a /MNT



2)boot bohdi

A) install kvm 0penbsd

 qemu-system-i386 -hda Q30.img -enable-kvm  -cdrom install58.iso -boot d -m 1024
( install58.iso is i386 snapshots   ) 


B) run kvm 0penbsd
qemu-system-i386 -enable-kvm -m 1024 -hda Q30.img   -net nic,macaddr=52:54:00:12:11:11 -net tap,ifname=tap0,script=/etc/qemu-ifup 


C) cd /; tar cvpf -   .  | ssh root@1.2.3.4     "cd /MNT ;  tar xpf -"



3) again on rental server

rewite /MNT/etc/fstab          <- disklabel sd0
 
installboot -r /MNT sd0


4)boot rental server by grub2


i can boot i386 openbsd of sd0a !







2nd story: ----------- for openbsd
1) run linux
     make kvm.img in sdb1 (ext2)   




 2)run openbsd
# mount_ext2fs /dev/sd1i /EXT2/

because of the weak ext2fs
# cp      /EXT2/OpenBSD-current.img   ./
# umount  /EXT2

# mount /dev/sd1a /MNT/

#qemu-system-x86_64 -m $1 -hda $2 -net nic,vlan=1,model=e1000,macaddr=fe:e1:ba:d3:e7:11 -net tap,vlan=1

# ssh -l tuyosi 192.168.100.115 (192.168.100.115 is kvm guest address)



# and on this qemu guest
rm -rf /usr/src/*
rm -rf /usr/obj/*
rm -rf /usr/xobj/*
rm -rf /usr/xenocara/*


cd /; tar cvpf -   .  | ssh root@192.168.100.101  "cd /MNT ;  tar xpf -"
                                (192.168.100.101 is kvm host address)
  and agein return to  qemu host
a)  rewite /MNT/etc/fstab   
       disklabel sd1
 
cat /MNT/etc/fstab   
9f39539222428a90.b none swap sw
#9f39539222428a90.a / ffs rw 1 1
#duid: 183119b913f9d677
183119b913f9d677.a / ffs rw 1 1
 
b)  installboot -r /MNT sd1


halt -p
boot by grun2

snapshots and sd1a appear , success!


 
3rd story  : for Linux




this gray part is written for japanese .     
the writing in english is later .
qemu-nbd をつかったものをかきます。
debiandog でしてます。

sda1はdebiandogで sda4に sda1にあるイメージTC.imgを実装します
したがってtinycoreのqemu イメージ /TC.imgはできた後の作業です。

    aptitude install  qemu-nbd

    # modprobe nbd max_part=8


    # qemu-nbd --connect=/dev/nbd0   /TC.img     

    # mount /dev/nbd0p1 /KVM

    mount  /dev/sda4  /MNT/
   (cd /KVM ; tar cvpf - .)|(cd /MNT ; tar xpf -)


     # umount /KVM
     # qemu-nbd --disconnect /dev/nbd0

     # umount /MNT

        edit /boot/grub/grub.cfg in /dev/sda1

 menuentry ' tc' {
 set root='hd0,msdos4'
 linux /tce/boot/vmlinuz
 initrd /tce/boot/core.gz

}

以上です。





on kvm host, lxle
mount  /dev/sdb1  /MNT

on  kvm guest , bean
cd /; tar cvpf -   .  | ssh root@192.168.100.101    "cd /MNT ;  tar xpf -"



again
on  kvm host, lxle
        edit /boot/grub/grub.cfg in /dev/sda1
menuentry 'bean' {
    set root='(hd1,msdos1)'
    linux    /boot/vmlinuz-3.2.0-89-generic root=UUID=d88f3df3-769d-4f79-b22a-8c2864cd555f ro  
    initrd    /boot/initrd.img-3.2.0-89-generic
}



another Linux specific method : 
this method is very secure because BEAN is not runnning .
[tar over ssh] method is copy running image to a partition , so there may be problems , so i think . 

on kvm host, lxle

    aptitude install  qemu-nbd

    # modprobe nbd max_part=8
    # qemu-nbd --connect=/dev/nbd0   /BEAN.img     # mount /dev/nbd0p1 /KVM



  mount  /dev/sda4  /MNT/
 (cd /mnt/kvm ; tar cvpf - .)|(cd /MNT/ ; tar xpf -)


edit    /MNT/etc/fstab

     # umount /KVM
     # qemu-nbd --disconnect /dev/nbd0

     # umount /MNT

        edit /boot/grub/grub.cfg in /dev/sda1
 menuentry ' tc' {
 set root='hd0,msdos4'
 linux /tce/boot/vmlinuz
 initrd /tce/boot/core.gz
}


apparently , changing sdb1 for sda3 is OK in Linux.
namely , 1 drive is OK ,
               but this setting does not fit to openbsd
               because  in openbsd 1 drive  should have only  1 openbsd file system .
                                 
perhaps other combination is possible .
 for example  kvm host is arch , and kvm guest is debian.
 but i did not try it yet .

about arch's qemu ,   see
   http://hatahata50.blogspot.jp/2015/10/arch-linux-qemu.html
                                                                                 (written in japanese)

real example is here !
http://qemuandopenbsd.blogspot.jp/2015/11/bohdi-arch20qcow2.html



the 4th story----------- only plan



archlinux machine is kvm supported intel machine
and
openbsd machine is i386 machine.

i386 machine cannot compile sources
                          becase of it's poor memory (256MB)


so
compaling current sources should be done on amd64 fast  PC
and
only binaly should be exported to old i386 machine .


why kvm ? -> if following current fails  , i only erase the kvm image file .
                and if succeed , back up is easy to copy  the kvm image file .
                openbsd lacks kvm module  , so openbsd's qemu is slow  .
            



overall view is next .

hub looks like internet .



i use 3 colours.

192.168.100.106

 

192.168.100.101 *about arch's kvm :
                               http://hatahata50.blogspot.jp/2015/10/arch-linux-qemu.html


192.168.100.116

1) on openbsd= 192.168.100.106
 mount /dev/sd1a  /MNT


2)on archlinux=192.168.100.101

a)boot archlinux

qemu-image create -f qcow2 OpenBSD-current.img 30G

B)install
qemu-system-i386 -m 1024 -hda OpenBSD-current.img -cdrom install58.iso(i386 current) -boot d   -net nic,vlan=1,model=e1000,macaddr=fe:e1:ba:d3:e7:11 -net tap,vlan=1


c)run
qemu-system-i386 -m 1024 -hda OpenBSD-current.img -net nic,vlan=1,model=e1000,macaddr=fe:e1:ba:d3:e7:11 -net tap,vlan=1

and
ssh -l tuyosi  192.168.100.106


3)on kvm's openbsd=192.168.100.116


when the follwing current is  finished (reboot and 2)'s run and ssh  )

ssh  root@192.168.100.106   "tar cvpf    -  /      | tar  xpf     - -C  /MNT

or
ssh  root@192.168.100.106   "tar czpf    -  /      | tar  xzpf     - -C  /MNT

or original is
ssh root@192.168.100.106   "tar czpf - / " | tar xzpf - -C /MNT

or

from ML
cd /; tar cfz -   | ssh root@real_machine        "cd /MNT;    tavfpz -"
correct miss typing 
cd /; tar cvpf -   .  | ssh root@192.168.100.106  "cd /MNT ;  tar xpf -"




4) on openbsd= 192.168.100.106

rewite /MNT/etc/fstab  <- disklabel wd1
 
 
installboot -r /MNT wd1
 
 

5) boot by grub2

 







Impossible Dream Don Quixote)

To dream the impossible dream
To fight  the unbeatable foe
To bear with unbearable sorrow
To run where the brave dare not go

To right the unrightable wrong
To love pure and chaste from a far
To try when your arms are too weary
To reach the unreachable star

This is my quest to follow that star
No matter how hopeless, no matter how far
To fight for the right
Without question or pause
To be willing to march
Into hell for a heavenly cause

And I know if I’ll only be true
To this glorious quest
That my heart will lie peaceful and calm
When I’m laid to my rest

And the world will be better for this
That one man, scorned and covered with scars
Still strove with his last ounce of courage
To reach the unreachable star
The fight the unbeatable foe
To dream the impossible dream


以下日本語で書きます。
 qemu~KVM にて 他のCPUをエミュレートしてコンパイルができます。
  失敗すれば KVMはファイルなので 消せばよい。
  成功すれば そのimage ファイルをコピーすれば バックアップできる。

また
cd /; tar cvpf -   .  | ssh root@1.2.3.4     "cd /MNT ;  tar xpf -"
にて実機に バイナリを送れます。
ということは x86_64 マシンさえあれば 純粋i386を作れます。

  32bit版では、2の32乗・・・つまり、約4GBのメモリが扱えるのに対して、
  64bit版では(理論上)2の64乗・・・つまり、16エクサバイトと言う
       とてつもなく大きなメモリが取り扱える事になりますが

CPU i386 、 メモリ  64MB ではコンパイル自体が無理です。



もちろん sparc64、powerPCもエミュレートできます。
その心は
http://gihyo.jp/dev/serial/01/vm_work/0001?page=2
仮想マシン上で動作するOSは
「そこに本物のハードウェアがある」と錯覚した状態で動作するため,使用するOS側に別途変更を加える必要がない点が魅力ですが,そのかわりに仮想マシンの実装は複雑になりがちです。
VMware,Hyper-V,KVMXenなどの主要な仮想マシンソフトウェアは,完全仮想化の方式をとっています。
 
 
よく考えると 
x86_64つまりamd64は i386を実行できるのだ。
だから 
なにもKVMの上でなくとも 純粋i386コーディングができるかは別として 実機でやればよい。
それで 
openbsdには amd64とi386の間にしか効かない
            kvm moduleがないのも頷ける。
 
したがって 
amd64の上で powepcを動かすとか(kvm効かないよ
危険なOSをkvm で動かすとか
linuxをしながら openbdのcurrentをKVMで追うとか
debug(自分の駄目ソースを実行したらOS自体まで壊した; 極例は rm -rf /
とかに使うべきだろう。 



ただ、もしも もしも
100Gメモリ core9な 64ビットPC で
純粋i386 OSを   純粋i386コンパイラーで
make world し 、 それを 
貧弱な i386 machine(CPUセレロン メモリ514M) に
実装できたら カ イ カ ン
その心は そのi386 machine には できないから。
なお 32bit PCでは メモリは 2の32乗で 4Gが限界
64bitでは さらに4Gx2x2x2.......x2(32回)なので まあ無限ですね。
 
 
linuxを起動し 、最初に openbsd current のイメージをコピーする。
それから openbsd current を kvm guestでたちあげて 
もっと新しいソースを追っかけている。
そして うまくいったらそれを 外付けHDDに実装してたしかめている。


fdisk -e sd1
edit 3

disklabel -E sd1
newfs sd1a
 
 
 https://www.youtube.com/watch?v=bqmWOSV--mE&spfreload=10


Korean soldier when the Vietnam War was added to the sexual assault 
against Vietnamese women .
But there is no apology from South Korea to Vietnam for this thing.
https://en.wikipedia.org/wiki/Phong_Nh%E1%BB%8B_and_Phong_Nh%E1%BA%A5t_massacre
 
 



https://www.youtube.com/watch?v=2oLmlYSJEy0
The term Lai Dai Han is a Vietnamese term for a mixed ancestry person 
born to a South Korean father 
and 
a Vietnamese mother (including the victims of Korean soldiers) 
during the Vietnam War
 
 Lai Dai Han often live at the margins of Vietnamese society. 
The South Korean government has not released an official statement 
regarding the sexual violence that took place during the Vietnam War.

2015年11月4日水曜日

レンタル サーバーを dual boot (debian + openbsd) にする



5)レンタル サーバーを dual boot(debian + openbsd)にする。

20GB分だけ まずdebianをいれます。

debian を起動し / に bsd.rd を保存します。
また fdisk で openbsd areaを確保ておきます。


/boot/grub/grub.cfg の
menuentry 'Debian GNU/Linux, with Linux 3.2.0-4-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu
 --class os {
    load_video
    insmod gzio
    insmod part_msdos
    insmod ext2
    set root='(hd0,msdos1)'
    search --no-floppy --fs-uuid --set=root 48513cc3-0824-41d2-b0e2-33cefa6dfbc7
    echo    'Loading Linux 3.2.0-4-amd64 ...'
    linux    /boot/vmlinuz-3.2.0-4-amd64 root=UUID=48513cc3-0824-41d2-b0e2-33cefa6dfbc7 ro single  
    echo    'Loading initial ramdisk ...'
    initrd    /boot/initrd.img-3.2.0-4-amd64
}
部分を



menuentry 'Debian GNU/Linux, with Linux 3.2.0-4-amd64 (recovery mode)' --class debian --class gnu-linux --class gnu
 --class os {
    load_video
    insmod gzio
    insmod part_msdos
    insmod ext2
    set root='(hd0,msdos1)'
    search --no-floppy --fs-uuid --set=root 48513cc3-0824-41d2-b0e2-33cefa6dfbc7
    echo    'Loading Linux 3.2.0-4-amd64 ...'
    kopenbsd /bsd.rd
    echo    'Loading initial ramdisk ...'
    boot
}

と書き換え この 'Debian GNU/Linux, with Linux 3.2.0-4-amd64 (recovery mode)'メ ニューで起動すると OPENBSDインストーラが動きます。 http での sd1へ の インストールとなります。 

その後もう一度 debian で立ち上げ

 cat /etc/grub.d/40_custom を
ーーーーーーーーーーーーー
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.

menuentry "OpenBSD" {
    set root=(hd0,4)
    chainloader +1
}

としてから update-grub するだけです。




ARCH linuxの最終の /boot/grub/grub.cfg は

menuentry 'Arch Linux, with Linux core repo kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-ad4103fa-d940-47ca-8506-301d8071d467' {
    load_video
    set gfxpayload=keep
    insmod gzio
    insmod part_msdos
    insmod ext2
    set root='hd0,msdos2'
    linux    /boot/vmlinuz-linux root=/dev/sdb2 rw  quiet

    initrd    /boot/initramfs-linux.img
}

menuentry 'openbsd' {
set  root='hd0,msdos1'
chainloader +1
}

menuentry 'INSTALL openbsd' {
kopenbsd /bsd.rd-57
boot
}








番外編) このサーバーは レン タルサーバーで動いてます。
お名前.comで メモリ1G HDD100GBです。

load averages:  0.07,  0.08,  0.12                                           aoiyuma.mydns.jp 15:16:43
46 processes: 45 idle, 1 on processor
CPU0 states:  0.0% user,  0.0% nice,  0.2% system,  0.0% interrupt, 99.8% idle
CPU1 states:  0.0% user,  0.0% nice,  0.0% system,  0.0% interrupt,  100% idle

Memory: Real: 271M/551M act/tot Free: 435M Cache: 197M Swap: 0K/2055M
  PID USERNAME PRI NICE  SIZE   RES STATE     WAIT      TIME    CPU COMMAND
 2817 _snort     4    0  502M  244M sleep     bpf       0:33  0.00% snort
 5383 root       2    0 1028K 1504K idle      select    0:21  0.00% sshd
24488 _syslogd   2    0 1120K 1484K idle      kqread    0:19  0.00% syslogd
 6203 tuyosi     2    0 3880K 2756K sleep     select    0:11  0.00% sshd
    1 root      10    0  524K  540K idle      wait      0:04  0.00% init
20705 _pflogd    4    0  684K  392K sleep     bpf       0:03  0.00% pflogd
16968 tuyosi     2    0 1436K 3780K sleep     kqread    0:01  0.00% imap
 3272 tuyosi     2    0 1444K 3848K sleep     kqread    0:01  0.00% imap
14486 _dovenul   2    0  948K 4372K sleep     kqread    0:01  0.00% imap-login

と スワップは2Gありますが、CPUは遊んでるような状態です。



# dmesg | grep wd
wd0 at pciide0 channel 1 drive 0: <QEMU HARDDISK>
wd0: 16-sector PIO, LBA48, 20480MB, 41943040 sectors

wd1 at pciide0 channel 1 drive 1: <QEMU HARDDISK>
wd1: 16-sector PIO, LBA48, 81920MB, 167772160 sectors

とハードディスクは QEMU HARDDISKで 想像するに実HDDではなくて
たぶん 数TBのハードディスクの一部なのでしょう。




# fdisk  wd0  
Disk: wd0       geometry: 2610/255/63 [41943040 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: 83    261  53  49 -    768  20  20 [     4196352:     8142848 ] Linux files* openbsdからもアクセスするためext2
*1: 83      0  32  33 -    261  53  48 [        2048:     4194304 ] Linux files* 
openbsdからもアクセスするため ext2
 2: 00      0   0   0 -      0   0   0 [           0:           0 ] unused     
 3: A6    768  20  21 -   2610 212  34 [    12339200:    29603840 ] OpenBSD    

と wd0は
4GBの arch (ここからもブート可)
2GBの arch ここに grub.cfgはある。もちろんブート可 /dev/wd0i      4128416   2299984   1618720    59%    /mnt-debian-sda2 と1Gちょっとしかいらない
menuentry 'openbsd install-5.7' {
kopenbsd /bsd.rd-57
}


menuentry 'openbsd install-snap' {
kopenbsd /bsd.rd-snap
}


menuentry 'Arch Linux sda111111' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        linux    /boot/vmlinuz-linux root=/dev/sda1 rw  quiet
        initrd   /boot/initramfs-linux.img
}
arch linuxは そのイメージを 
sftp -i vps1006-001.key  iu1-00008@sftp1001.myvps.jp
な形で転送して、これが仮想CDとなってお名前でOインストールをします。

arch linuxは そのgrubブートローダーを使うだけですから、スワップもいりませんし GUIもいりません。
だから2GBのHDDへも十分入ります。
そしてこのext2に openbsdの必要最小限をバックアップしてます。
/etc, /var/www, /home/tuyosi/*.bat ですね。
そうして万一のクラッシュに備えてます。
80G openbsd クラッシュ -> 15B openbsd クラッシュ -> arch のブートローダでkopenbsd を利用して再インストのあと/etc, /var/www, /home/tuyosi/*.batを
を書き戻して早い普及をはかる。
15GBのopenbsd   (ここからもブート可)

# fdisk  wd1
Disk: wd1       geometry: 10443/255/63 [167772160 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: 00      0   0   0 -      0   0   0 [           0:           0 ] unused     
 1: 00      0   0   0 -      0   0   0 [           0:           0 ] unused     
 2: 00      0   0   0 -      0   0   0 [           0:           0 ] unused     
*3: A6      0   1   2 -  10442 254  63 [          64:   167766731 ] OpenBSD  

80GBあって 通常はここから起動している。
今もこの状態。

Filesystem  512-blocks      Used     Avail Capacity  Mounted on
/dev/wd1a    160966480  39509296 113408860    26%    /
と十分な余裕があります。












openbsd で teamviewer を ブロックする

3) BLOCK teamviewer by openbsd

 eamviewer は 通 常のfirewallを乗り越え内部に侵入していきます。


openbsd
pfだ けでは防御不能です。
例えば会社の内部の一台で teamviewerが 起動しているとIDPASSWDで そのPCに入られま す。
そのPCを から他のPCに 接続して、中の情報を抜き取られます。
そのために 以下の方法でteamviewer をブロックします。
つまり squidを あわせて使います。






BLOCK  teamviewer by openbsd
teamviewer は 通 常のfirewallを乗り越え内部に侵入していきます。

openbsd
のpfだけでは防御不能です。
例えば会社の内部の一台で teamviewerが起動しているとIDPASSWDで そのPCに入られます。
そのPCをから他のPCに 接続して、中の情報を抜き取られます。
そのために 以下の方法でteamviewer をブロックします。
つまり squidをあわせて使います。


下のような構成で windows81 が linuxの teamserver にはいていくのを
openbsdが止めます。

internet
|
wifi router---windows81
|
urtwn0 dhcp
openbsd:(fire wall=pf+squid)
fxp0 192.168.64.1/24(dhcpd)
|
dhcp
linux




in order to access internet by linux PC
(firefox edit>preference>adavance>setting>http proxy 192.168.64.1 port 3128




# ./comment-out.bat  /etc/squid/squid.conf                                                                  
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3128
coredump_dir /var/squid/cache
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320



# ./comment-out.bat  /etc/pf.conf                                                                           
ext_if="urtwn0"
int_if="fxp0"
tcp_services="{ 22, 113 }"
icmp_types="echoreq"
set block-policy return
set loginterface $ext_if
set skip on lo
set reassemble yes no-df
pass in quick log on $ext_if inet proto tcp to port 80 divert-to 127.0.0.1 port 3128
pass out quick from 127.0.0.1 divert-reply
anchor "ftp-proxy/*"
pass in quick on $int_if inet proto tcp to any port ftp \
    divert-to 127.0.0.1 port 8021
block in log
pass out quick
antispoof quick for { lo $int_if }
pass in  on  $ext_if   inet proto tcp from any to  ( $ext_if:0 ) port  $tcp_services
pass in inet proto icmp all icmp-type $icmp_types
pass in on $int_if






すると win81  のteamviewer から linuxteamviewer に接続しよ うとしても
パー トナーへの接続はありません
となって接続を拒否される。
つまり openbsd firewall が侵入を食い止めた。



ということでサーバーとして使うなら やはりopenbsdが簡単で 堅牢 です。
特に ftpサーバー設定でその違い がわかるでしょう。
ただしGUIは下手です。

そのため自分はarch linuxを 使ってます。
これなら 2015/7/5の 時点で カーネルは
uname -r
4.0.7-2-ARCH
と最新になってます。










私見ですが、teamviewerをしこまれたPCは 「私はここよ。 私の声に乗って私を連れに来て」と 80番ポー ト?で声をあげます。 従ってどこにいてもteamviewerでそこに入っていけます。
も し万一このPCに起爆装置がつながっていたら、遠隔操作で爆発します。
も しカメラがつながっていたら盗撮ですし、 マイクならば盗聴されます。
便 利ですが ドローン並みに危ない面があります。

unbound について

4)  unbound
/etc/resolv.conf nameserver 127.0.0.1 にして /etc/rc.d/unbound -f restart だけで動きます。
http://gihyo.jp/admin/feature/01/unbound/0001  によると以下です。
Unbound は本来はキャシュサーバーなのですが、簡易的なコンテンツサーバとしての機能を持ち,LAN内 のホストの名前の解決などに利用できます。 
なおDNSコ ンテンツサーバは権威サーバとも呼ばれ,自身が権威を持っているゾーンに対する問い合わせのみに回答します。
参考: http://murasaki.cocolog-nifty.com/cloud/2009/07/unbound-1f2d.html




全体の状況は

internet
|
|
|
run0:dhcp
<openbsd(mail+dhcpd server)>
bge0:192.168.11.1
|
|
|
fxp0:dhcp
<PC>

PC send and revieve mail by sylpheed .



サーバーの /etc/dhcpd.intefaces                                       
bge0


サーバーの /etc/dhcpd.conf                                            
option  domain-name-servers 192.168.11.1;
subnet 192.168.11.0 netmask 255.255.255.0 {
        option routers 192.168.11.1;
        range 192.168.11.50 192.168.11.57;
}


サーバーの /etc/resolv.conf                                           
nameserver 127.0.0.1

############# 

以下は不安定ですが 一応ローカルLANでメールの送受信ができます。


/var/unbound/etc/unbound.conf                                        <
-----------------
server:
        interface: 127.0.0.1
        interface: ::1
        access-control: 0.0.0.0/0 refuse
        access-control: 127.0.0.0/8 allow
        access-control: ::0/0 refuse
        access-control: ::1 allow
        hide-identity: yes
        hide-version: yes
###############################--->join name & adress
        interface: 192.168.11.1
        access-control: 192.168.11.0/24 allow
        local-zone: "home." static
        local-data: "server.home.  IN A 192.168.11.1"
        local-data: "kerai.home. IN A 192.168.11.50"
        local-data-ptr: "192.168.11.1   server.home."
        local-data-ptr: "192.168.11.50   kerai.home."
###############################--->to build mail server
 local-data: "home. IN MX 10 server.home."
 local-data-ptr: "192.168.11.1   server.home."



#  /etc/hosts                                                 
-------------------------
127.0.0.1       localhost
::1             localhost
192.168.100.101 aoiyuma.mydns.jp
192.168.11.1    server.home


 
# /etc/myname                                                
-------------------------
aoiyuma.mydns.jp



# /etc/postfix/main.cf                                       
------------------------------------------
myhostname = server.home
mydomain = home
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname localhost.$mydomain
home_mailbox = Maildir/
mynetworks = 192.168.11.0/24, 127.0.0.0/8
queue_directory = /var/spool/postfix
command_directory = /usr/local/sbin
daemon_directory = /usr/local/libexec/postfix
data_directory = /var/postfix
mail_owner = _postfix
inet_protocols = all
unknown_local_recipient_reject_code = 550
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/local/sbin/sendmail
newaliases_path = /usr/local/sbin/newaliases
mailq_path = /usr/local/sbin/mailq
setgid_group = _postdrop
html_directory = /usr/local/share/doc/postfix/html
manpage_directory = /usr/local/man
sample_directory = /etc/postfix
readme_directory = /usr/local/share/doc/postfix/readme
meta_directory = /etc/postfix
shlib_directory = no





/etc/postfix/master.cf                                        
--------------------------------------
smtp      inet  n       -       -       -       -       smtpd
pickup    unix  n       -       -       60      1       pickup
cleanup   unix  n       -       -       -       0       cleanup
qmgr      unix  n       -       -       300     1       qmgr
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       -       -       -       smtp
relay     unix  -       -       -       -       -       smtp
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
retry     unix  -       -       -       -       -       error
discard   unix  -       -       -       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       -       -       -       lmtp
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache



/etc/dovecot/dovecot.conf                                        <
protocols = imap
listen = *
!include conf.d/*.conf




/etc/dovecot/conf.d/10-mail.conf  
   mail_location = maildir:~/Maildir
namespace inbox {
  inbox = yes
}
mmap_disable = yes
first_valid_uid = 1000
mail_plugin_dir = /usr/local/lib/dovecot
mbox_write_locks = fcntl





/etc/dovecot/conf.d/10-master.conf                                        
<
service imap-login {
  inet_listener imap {
  }
  inet_listener imaps {
  }
}
service pop3-login {
  inet_listener pop3 {
  }
  inet_listener pop3s {
  }
}
service lmtp {
  unix_listener lmtp {
  }
}
service imap {
}
service pop3 {
}
service auth {
  unix_listener auth-userdb {
  }
}
service auth-worker {
}
service dict {
  unix_listener dict {
  }
}





 /etc/dovecot/conf.d/10-auth.conf 
auth_mechanisms = plain login
!include auth-system.conf.ext
disable_plaintext_auth = no





/etc/dovecot/conf.d/10-ssl.conf                                        <
ssl = yes
ssl_cert = </etc/ssl/dovecotcert.pem
ssl_key = </etc/ssl/private/dovecot.pem






あとは sylpheed で
メールアドレス t@server.home
imap
送受信さーばー ともに server.home
高度な設定でポートを25と143
にするだけです。