2015年8月24日月曜日

無線を有線に変換 (TVをインターネットにつなげる) NAT

(TV)
nic
|
fxp0
(libretto:OpenBSD)
rum0

 電波

wifi router
というふうに お蔵入りしているlibrettoを仲介して
TVをインターネットにつなげます。






0)余分なこと(openbsd の pxe install
/tftp
bsd.rd
pxeboot
etc

cat etc/boot.conf
boot tftp:/bsd.rd


1)まず予備実験です。

(hp PC)
nic
|
HUB
|
fxp0
(libretto:OpenBSD)
rum0
|
wireless
|
(fon)
nic
|
nic
router

openbsd

./comment-out.bat /etc/hostname.fxp0                                                      
inet 192.168.200.1 255.255.255.0



 ./comment-out.bat /etc/hostname.rum0 
nwid MyPlace
wpakey 702446
dhcp



# ./comment-out.bat/etc/dhcpd.interfaces                                                         
fxp0





# ./comment-out.bat /etc/dhcpd.conf                                                               
option domain-name-servers 8.8.8.8;
subnet 192.168.200.0 netmask 255.255.255.0 {
    option routers 192.168.200.1;
    range 192.168.200.200  192.168.200.209;
}


# ./comment-out.bat tv.bat                                                                        
/home/tuyosi/wifi.bat  <ーー>代わりに sh /etc/netstart でもいいかも
ifconfig -a| grep 192
echo 'dhcpd------------'
/etc/rc.d/dhcpd -f restart
cp /etc/resolv.conf-127 /etc/resolv.conf
echo 'unbound----------'
/etc/rc.d/unbound -f restart
sysctl net.inet.ip.forwarding=1
pfctl -f /etc/pf.tv
pfctl -sr
ping -c 3 www.google.com



 ./comment-out.bat wifi.bat                                                                      
ifconfig   rum0 down
ifconfig   rum0 nwid "MyPlace" wpakey "70846" up
dhclient rum0



2)本格運用
予備実験との大きな差は DNS つまり unbound を動かさないといけません。

(TV)
nic
|
fxp0
(libretto:OpenBSD)
rum0

 電波

wifi router

1)dhcp サーバー
 ./comment-out.bat /etc/hostname.fxp0                                                                                      
inet 192.168.12.1 255.255.255.0


 # ./comment-out.bat /etc/dhcpd.interfaces                                                                                    fxp0






# ./comment-out.bat /etc/dhcpd.conf                                                                                        
option  domain-name-servers 8.8.8.8;
subnet 192.168.12.0 netmask 255.255.255.0 {
        option routers 192.168.12.1;
filename "pxelinux.0";
        range 192.168.12.10 192.168.12.15;
}



2)unbound
#  ./comment-out.bat /etc/resolv.conf
nameserver 127.0.0.1




#  ./comment-out.bat /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
        interface: 192.168.12.1
        access-control: 192.168.12.0/24 allow
        local-zone: "home." static
        local-data: "server.home.  IN A 192.168.12.1"
        local-data: "kerai.home. IN A 192.168.12.50"
        local-data-ptr: "192.168.12.1   server.home."
        local-data-ptr: "192.168.12.10   kerai10.home."
        local-data-ptr: "192.168.12.11   kerai11.home."
local-data: "home. IN MX 10 server.home."
local-data-ptr: "192.168.12.1   server.home."




3)シェルスクリプトなど
# ./comment-out.bat /home/tuyosi/wifi.bat-rum0                                                                              
ifconfig rum0 down
ifconfig rum0 nwid "URoad-662EA0" wpakey "04271" up
dhclient rum0



でrum0を wifi routerにつなげます・



# ./comment-out.bat /etc/resolv.conf-127      

nameserver 127.0.0.1

これは unboundを動かすためです。


# ./comment-out.bat /etc/pf.tv-rum0     
ext_if="rum0"
int_if="fxp0"
match out on $ext_if inet from ($int_if:network) to any nat-to ($ext_if:0)
pass in   on $int_if
pass out  on $int_if
pass in   on $ext_if
pass out  on $ext_if



 ./comment-out.bat tv.bat                                                                                                  
/etc/rc.d/syslogd stop
/etc/rc.d/pflogd  stop
/etc/rc.d/smtpd   stop
/etc/rc.d/sndiod  stop
/etc/rc.d/cron    stop
 

/home/tuyosi/wifi.bat-rum0

cp /etc/resolv.conf-127 /etc/resolv.conf
echo 'unbound----------'
/etc/rc.d/unbound -f restart
 

sysctl net.inet.ip.forwarding=1
pfctl -f /etc/pf.tv-rum0



で起動します。