2015年10月26日月曜日

arch linux qemu

石川や 浜の真砂は 尽きるとも
       世に盗人の 種は尽きまじ


qemuでインターネットです
まず バカチョンを 見せます 
 ctrl + alt + G でマウスの焦点を変えます

1) pacman -S qemu bridge-utils libvirt




2)  ifconfig をして下の黄色を変えます

cat /etc/netctl/bridge
Description="Example Bridge connection"
Interface=br0
Connection=bridge
BindsToInterfaces=(enp9s0 tap0)
IP=dhcp



3)
cat /etc/qemu-ifup
#!/bin/sh
echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /usr/bin/ip link set $1 up promisc on
echo "Adding $1 to br0..."
sudo /usr/bin/brctl addif br0 $1
sleep 2


chmod 750 /etc/qemu-ifup

 
4)
cat /etc/qemu-ifdown
#!/bin/sh

echo "Executing /etc/qemu-ifdown"
sudo /usr/bin/ip link set $1 down
sudo /usr/bin/brctl delif br0 $1
sudo /usr/bin/ip link delete dev $1


chmod 750 /etc/qemu-ifdown


 5)

qemu-img create -f qcow2 Q20.img 20G
 

 qemu-system-x86_64 -m 3072 -hda Q20.img -cdrom ./install60.iso  -boot d

modprobe tun
sysctl net.ipv4.ip_forward=1
systemctl start libvirtd
netctl start bridge


qemu-system-x86_64  -m 3072 -hda Q20.img -net nic,macaddr=52:54:00:12:11:11 -net tap,ifname=tap0,script=/etc/qemu-ifup



以上です。
ただ 上ではkvmは 使ってません。 

bios でkvmができるようにすると
  # modprobe -r kvm_intel 
  # modprobe kvm_intel nested = 1
したあと

qemu-system-x86_64  -m 3072 -enable-kvm  -hda Q20.img -net nic,macaddr=52:54:00:12:11:11 -net tap,ifname=tap0,script=/etc/qemu-ifup
となります


これから 詳しく書きます。
debian系は qemu kvm 簡単だけど archは難しい
GUIの virt-managet , gnome-boxes, qtemu はうまく動かない。

それで
http://lazy-dog.hatenablog.com/entry/2014/07/13/015538
をみたが、
自分のは dhcpcd なので
/etc/netctl/enp2s0_configがない。
それにかなり複雑である。

それで
https://wiki.archlinuxjp.org/index.php/QEMU の以下の部分へ逃げた。
------------------------------------------------------------------------------------------->

ブリッジを手動で作成する
おそらく一番よく使われている設定です。


この設定では、物理的なホストマシンと同一の Ethernet セグメントに、

直接外部ネットワークに仮想マシンが位置するようになります。

通常の Ethernet アダプタをブリッジアダプタで置き換えて、
通常の Ethernet アダプタをブリッジアダプタに bind することにします。

  • ブリッジを制御するための brctl が入っている bridge-utils をインストール。

  • IPv4 フォワーディングを有効にする:

# sysctl net.ipv4.ip_forward=1
変更を永続的にするために、/etc/sysctl.d/99-sysctl.confnet.ipv4.ip_forward = 0net.ipv4.ip_forward = 1 に変えます。

  • tun モジュールをロードして起動時にロードするように設定してください。詳しくはカーネルモジュールを参照。

  • ブリッジを作成します。詳しくは netctl でブリッジ接続を見て下さい。
    ブリッジの名前を br0 にするか、
    下のスクリプトを使用するブリッジの名前に忘れずに変更してください。

  • QEMU 用に root:kvm 750 パーミッションで tap アダプタを立ち上げるスクリプトを作成:

/etc/qemu-ifup

#!/bin/sh
  
echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /usr/bin/ip link set $1 up promisc on
echo "Adding $1 to br0..."
sudo /usr/bin/brctl addif br0 $1
sleep 2

  • Create the script that QEMU uses to bring down the tap adapter in /etc/qemu-ifdown with root:kvm 750 permissions:

/etc/qemu-ifdown

#!/bin/sh
 
echo "Executing /etc/qemu-ifdown"
sudo /usr/bin/ip link set $1 down
sudo /usr/bin/brctl delif br0 $1
sudo /usr/bin/ip link delete dev $1

----------------------------------------------------------------------<


これを元に始めます。

1)
pacman -S qemu bridge-utils libvirt





2)
qemu-img create -f qcow2 Q10.img 10G







3) install OS (cd is openbsd)
qemu-system-x86_64 -m 2048 -hda Q10.img -cdrom ./install60.iso  -boot d

4)
cat /etc/netctl/bridge
Description="Example Bridge connection"
Interface=br0
Connection=bridge
BindsToInterfaces=(enp9s0 tap0)
IP=dhcp



cat /etc/qemu-ifup
#!/bin/sh
echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /usr/bin/ip link set $1 up promisc on
echo "Adding $1 to br0..."
sudo /usr/bin/brctl addif br0 $1
sleep 2


chmod 750 /etc/qemu-ifup

cat /etc/qemu-ifdown
#!/bin/sh

echo "Executing /etc/qemu-ifdown"
sudo /usr/bin/ip link set $1 down
sudo /usr/bin/brctl delif br0 $1
sudo /usr/bin/ip link delete dev $1



chmod 750 /etc/qemu-ifdown


5) preparing to start

modprobe tun
sysctl net.ipv4.ip_forward=1
systemctl start libvirtd
netctl start bridge



6) ここは普通ですね
qemu-system-x86_64 -m 2048 -hda Q10.img \

-net nic,macaddr=52:54:00:12:11:11 \ 
-net tap,ifname=tap0,script=/etc/qemu-ifup





then openbsd start and is given address by router(192.168.1.1)
and can ping www.google.com.


 
internet
      |
 router
 192.168.1.1
      |
enp9s0 : dhcp---->br0 :192.168.1.226
|    arch 
|
tap
|
|
em0: 192.168.1.217
qemu:openbsd



7)but sometimes  arch itself cannot ping www.google.com.


this is trouble .
so in arch linux
netctl restart bridge


and then
arch  can ping www.google.com.

i found
(process:689): GLib-WARNING **: gmem.c:482: custom memory allocation vtable not supported
this may be the  necessity of  [ netctl restart bridge ]


どうなってるかというと
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
in arch
ifconfig -a
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.226  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 2001:c90:8a71:c0d8:25e7:6897:2eb3:87dc  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::21e:c9ff:fe05:78fc  prefixlen 64  scopeid 0x20<link>
        ether 00:1e:c9:05:78:fc  txqueuelen 0  (Ethernet)
        RX packets 10264  bytes 11209813 (10.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4661  bytes 557618 (544.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


enp9s0: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500
        ether 00:1e:c9:05:78:fc  txqueuelen 1000  (Ethernet)
        RX packets 10360  bytes 11401261 (10.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4703  bytes 580080 (566.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 17 


lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 989  bytes 189431 (184.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 989  bytes 189431 (184.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


tap0: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500
        ether f2:3a:c6:2d:e7:4c  txqueuelen 500  (Ethernet)
        RX packets 65  bytes 9200 (8.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1257  bytes 392221 (383.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0









in openbsd (the folowing is get by ssh -l XXX 192.168.1.217 on arch)

Last login: Mon Oct 26 18:51:11 2015 from 192.168.1.226
OpenBSD 5.7 (GENERIC) #738: Sun Mar  8 10:59:31 MDT 2015
Welcome to OpenBSD: The proactively secure Unix-like operating system.
Please use the sendbug(1) utility to report bugs in the system.
Before reporting a bug, please try to reproduce it with the latest
version of the code.  With bug reports, please try to ensure that
enough information to reproduce the problem is enclosed, and if a
known fix for it exists, include that as well.
$ su
Password:
# ifconfig -a                                                                                                               
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 32768
        priority: 0
        groups: lo
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
        inet6 ::1 prefixlen 128
        inet 127.0.0.1 netmask 0xff000000
 

em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        lladdr 52:54:00:12:11:11
        priority: 0
        groups: egress
        media: Ethernet autoselect (1000baseT full-duplex)
        status: active
        inet 192.168.1.217 netmask 0xffffff00 broadcast 192.168.1.255
 

enc0: flags=0<>
        priority: 0
        groups: enc
        status: active
 

pflog0: flags=141<UP,RUNNING,PROMISC> mtu 33192
        priority: 0
        groups: pflog






最終的提案は



1) cat /etc/resolv.conf.head
nameserver 8.8.8.8




2) cat qemu-Memory-Image.bat

# modprobe kvm_intel nested=1
modprobe tun

sysctl net.ipv4.ip_forward=1
systemctl start libvirtd
netctl start bridge

qemu-system-x86_64 -enable-kvm -m 1024 -hda kvm.img -net nic,macaddr=52:54:00:12:11:11 -net tap,ifname=tap0,script=/etc/qemu-ifup

netctl restart bridge



すぐには host側で ping www.google.com ができず
時間遅れ 15秒位かが発生します

仮想化のネスト https://wiki.archlinuxjp.org/index.php/KVM

Nested Virtualization を使うことで、
元の仮想マシンやネットワークに修正を加えることなく
、既存の仮想マシンを 
別のハイパーバイザーや他のクラウド上で動作させることができるようになります。

ホスト側で、kvm_intel の nested 機能を有効にしてください:
# modprobe -r kvm_intel
# modprobe kvm_intel nested=1

永続化させるには (カーネルモジュール#モジュールオプションを設定するを参照):
/etc/modprobe.d/modprobe.conf
options kvm_intel nested=1

機能が有効になっているか確認:
$ systool -m kvm_intel -v | grep nested
    nested              = "Y"

次のコマンドでゲスト VM を実行してください:
$ qemu-system-x86_64 -enable-kvm -cpu host
VM を起動したら vmx フラグが存在するか確認:

$ grep -E "(vmx|svm)" /proc/cpuinfo




machine  translation












arch linux qemu


i follow  wiki.archlinuxjp.org/index.php/QEMU.
-------------------------------------------------- ----------------------------------------->

You want to create a bridge manually
Probably is the most well-used are set.
In this configuration, the same Ethernet segment and physical host machine,
Direct looks like the external network to a virtual machine is located.

By replacing the normal Ethernet adapter bridge adapter,
We decided to bind the normal Ethernet adapter to the bridge adapter.

  • To control the bridge brctl is in bridge-utils and install.

  • To enable IPv4 forwarding:

  # Sysctl net.ipv4.ip_forward = 1 
 
In order to make permanent changes, /etc/sysctl.d/99-sysctl.conf of net.ipv4.ip_forward = 0 the net.ipv4.ip_forward = 1 to change it to.

  • tun please be configured to load at startup by loading the module. For more kernel modules see.

  • It will create a bridge. For more information bridge connection in netctl see the.
    The name of the bridge br0 Either,
    Please change not forget the name of the bridge to be used under the script.

  • For QEMU root:kvm to create a script to launch the tap adapter at 750 permission:

  / Etc / qemu-ifup 

  #! / Bin / sh 
  
  echo "Executing / etc / qemu-ifup" 
  echo "Bringing up $ 1 for bridged mode ..." 
  sudo / usr / bin / ip link set $ 1 up promisc on 
  echo "Adding $ 1 to br0 ..." 
  sudo / usr / bin / brctl addif br0 $ 1 
  sleep 2 
 

  • Create the script That QEMU the uses to Bring down the tap adapter in /etc/qemu-ifdown with root:kvm 750 Permissions:

  / Etc / qemu-ifdown 

  #! / Bin / sh 
 
  echo "Executing / etc / qemu-ifdown" 
  sudo / usr / bin / ip link set $ 1 down 
  sudo / usr / bin / brctl delif br0 $ 1 
  sudo / usr / bin / ip link delete dev $ 1 
 

-------------------------------------------------- -------------------- <


It will start this to the original.

1)
pacman -S qemu bridge-utils libvirt




2)
qemu-img create -f qcow2 Q5.img 5G






3) install OS (cd is openbsd)
qemu-system-i386 -m 128 -hda Q5.img -cdrom / dev / sr0 -boot d




4)
cat / etc / netctl / bridge
Description = "Example Bridge connection"
Interface = br0
Connection = bridge
BindsToInterfaces = (enp9s0 tap0)
IP = dhcp


cat / etc / qemu-ifup
#! / Bin / sh
echo "Executing / etc / qemu-ifup"
echo "Bringing up $ 1 for bridged mode ..."
sudo / usr / bin / ip link set $ 1 up promisc on
echo "Adding $ 1 to br0 ..."
sudo / usr / bin / brctl addif br0 $ 1
sleep 2


cat / etc / qemu-ifdown
#! / Bin / sh
echo "Executing / etc / qemu-ifdown"
sudo / usr / bin / ip link set $ 1 down
sudo / usr / bin / brctl delif br0 $ 1
sudo / usr / bin / ip link delete dev $ 1





5) preparing to start

modprobe tun
sysctl net.ipv4.ip_forward = 1
systemctl start libvirt d
netctl start bridge



6) where it is the ordinary
qemu-system-i386 -m 128 -hda Q-5.img \
-net nic, macaddr = 52:54: 00: 12: 11: 11 \
-net tap, ifname = tap0, script = / etc / qemu-ifup





then openbsd start and is given address by router (192.168.1.1)
and I CAN ping www.google.com .

 
internet
|
router
  192.168.1.1
|
enp9s0: dhcp ----> br0: 192.168.1.226
|     arch
|
tap
|
|
em0: 192.168.1.217
qemu: openbsd



7) but sometimes arch Itself CAN not ping www.google.com .


this is trouble.
so in arch linux
netctl restart bridge

and then
arch CAN ping www.google.com .

i found
(Process: 689): GLib-WARNING **: gmem.c: 482: custom memory allocation vtable not supported
this may be the necessity of [netctl restart bridge]


If you say it and how are made
  :::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::
in arch
ifconfig -a
br0: flags = 4163 <UP, BROADCAST, RUNNING, MULTICAST> mtu 1500
inet 192.168.1.226 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 2001: c90: 8a71: c0d8: 25e7: 6897: 2eb3: 87dc prefixlen 64 scopeid 0x0 <global>
inet6 fe80 :: 21e: c9ff: fe05: 78fc prefixlen 64 scopeid 0x20 <link>
ether 00: 1e: c9: 05: 78: fc txqueuelen 0 (Ethernet)
RX packets 10264 bytes 11209813 (10.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4661 bytes 557618 (544.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp9s0: flags = 4419 <UP, BROADCAST, RUNNING, PROMISC, MULTICAST> mtu 1500
ether 00: 1e: c9: 05: 78: fc txqueuelen 1000 (Ethernet)
RX packets 10360 bytes 11401261 ​​(10.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4703 bytes 580080 (566.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 17

lo: flags = 73 <UP, LOOPBACK, RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 :: 1 prefixlen 128 scopeid 0x10 <host>
loop txqueuelen 0 (Local Loopback)
RX packets 989 bytes 189431 (184.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 989 bytes 189431 (184.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

tap0: flags = 4419 <UP, BROADCAST, RUNNING, PROMISC, MULTICAST> mtu 1500
ether f2: 3a: c6: 2d: e7: 4c txqueuelen 500 (Ethernet)
RX packets 65 bytes 9200 (8.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1257 bytes 392221 (383.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

:::::::::::::::::::::::::::::::::::::::::::::::::: ::::::






in openbsd (the folowing is get by ssh -l XXX 192.168.1.217 on arch)

Last login: Mon Oct 26 18:51:11 2015 from 192.168.1.226
OpenBSD 5.7 (GENERIC) # 738: Sun Mar 8 10:59:31 MDT 2015
Welcome to OpenBSD: The proactively secure Unix-like operating system.
Please use the sendbug (1) utility to report bugs in the system.
Before reporting a bug, please try to reproduce it with the latest
version of the code. With bug reports, please try to ensure that
enough information to reproduce the problem is enclosed, and if a
known fix for it exists, include that as well.
$ Su
Password:
# Ifconfig -a
lo0: flags = 8049 <UP, LOOPBACK, RUNNING, MULTICAST> mtu 32768
priority: 0
groups: lo
inet6 fe80 :: 1% lo0 prefixlen 64 scopeid 0x3
inet6 :: 1 prefixlen 128
inet 127.0.0.1 netmask 0xff000000

em0: flags = 8843 <UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST> mtu 1500
lladdr 52: 54: 00: 12: 11: 11
priority: 0
groups: egress
media: Ethernet autoselect (1000baseT full-duplex)
status: active
inet 192.168.1.217 netmask 0xffffff00 broadcast 192.168.1.255

enc0: flags = 0 <>
priority: 0
groups: enc
status: active

pflog0: flags = 141 <UP, RUNNING, PROMISC> mtu 33192
priority: 0
groups: pflog

:::::::::::::::::::::::::::::::::::::::::::::::::: :::




When you turn on the various OS
Might be lurking is Toka malicious something virus in it.
In observed in qemu.
impact on the mother ship if this would be unlikely.



The final proposal



1) cat /etc/resolv.conf.head
nameserver 8.8.8.8



2) cat qemu-Memory-Image.bat
# Modprobe kvm_intel nested = 1
modprobe tun
sysctl net.ipv4.ip_forward = 1
systemctl start libvirtd
netctl start bridge
qemu-system-x86_64 -enable-kvm -m 1024 -hda kvm.img -net nic, macaddr = 52: 54: 00: 12: 11: 11 -net tap, ifname = tap0, script = / etc / qemu-ifup
netctl restart bridge

You can not ping www.google.com in the host side immediately
Time delay of 15 seconds position or will occur

Nest of virtualization https://wiki.archlinuxjp.org/index.php/KVM

By using the Nested Virtualization,
Without modification to the original virtual machine and network
, An existing virtual machine  
And it will be able to operate on different hypervisor or other clouds.

On the host side, kvm_intel Please enable nested function of:
  # Modprobe -r kvm_intel 
  # Modprobe kvm_intel nested = 1

To perpetuate ( to set the kernel module # module options see):
  /etc/modprobe.d/modprobe.conf 
  options kvm_intel nested = 1

Check whether the feature is enabled:
  $ Systool -m kvm_intel -v | grep nested 
  nested = "Y"

Please run the guest VM with the following command:
  $ Qemu-system-x86_64 -enable-kvm -cpu host 
 
Check for vmx flag Once you start the VM is present:

  $ Grep -E "(vmx | svm)" / proc / cpuinfo 
 


2015年8月12日水曜日

dhcpd server にする、 grub

internet
|
wifi router
|
wlp0s29f7u1
arch
enp9s0:192.168.11.1
|
dhcp
debian

という構成です。
 

ifconfig enp9s0 192.168.11.1
でまず enp9s0
にアドレスをあてます。









それから dhcpd サーバーを構成します。
 /etc/dnsmasq.conf
server=/11.168.192.in-addr.arpa/8.8.8.8
interface=enp9s0
dhcp-range=192.168.11.50,192.168.11.150,12h




1行めで ネームサーバーを指定してます。






内のを外に出すために morizotを利用します

morizot.bat
SYSCTL="/sbin/sysctl -w"
IPT="/usr/sbin/iptables"
IPTS="/usr/sbin/iptables-save"
IPTR="/usr/sbin/iptables-restore"
INET_IFACE="wlp0s29f7u1"
LOCAL_IFACE="enp9s0"
LOCAL_IP="192.168.11.1"
LOCAL_NET="192.168.11.0/24"
LOCAL_BCAST="192.168.11.255"
LO_IFACE="lo"
LO_IP="127.0.0.1"
if [ "$1" = "save" ]
then
    echo -n "Saving firewall to /etc/sysconfig/iptables ... "
    $IPTS > /etc/sysconfig/iptables
    echo "done"
    exit 0
elif [ "$1" = "restore" ]
then
    echo -n "Restoring firewall from /etc/sysconfig/iptables ... "
    $IPTR < /etc/sysconfig/iptables
    echo "done"
    exit 0
fi
echo "Loading kernel modules ..."
/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/ip_forward
else
    $SYSCTL net.ipv4.ip_forward="1"
fi
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/tcp_syncookies
else
    $SYSCTL net.ipv4.tcp_syncookies="1"
fi
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
else
    $SYSCTL net.ipv4.conf.all.rp_filter="1"
fi
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
else
    $SYSCTL net.ipv4.icmp_echo_ignore_broadcasts="1"
fi
if [ "$SYSCTL" = "" ]
then
    echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
else
    $SYSCTL net.ipv4.conf.all.accept_source_route="0"
fi
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/conf/all/secure_redirects
else
    $SYSCTL net.ipv4.conf.all.secure_redirects="1"
fi
if [ "$SYSCTL" = "" ]
then
    echo "1" > /proc/sys/net/ipv4/conf/all/log_martians
else
    $SYSCTL net.ipv4.conf.all.log_martians="1"
fi
echo "Flushing Tables ..."
$IPT -P INPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -t nat -P PREROUTING ACCEPT
$IPT -t nat -P POSTROUTING ACCEPT
$IPT -t nat -P OUTPUT ACCEPT
$IPT -t mangle -P PREROUTING ACCEPT
$IPT -t mangle -P OUTPUT ACCEPT
$IPT -F
$IPT -t nat -F
$IPT -t mangle -F
$IPT -X
$IPT -t nat -X
$IPT -t mangle -X
if [ "$1" = "stop" ]
then
    echo "Firewall completely flushed!  Now running with no firewall."
    exit 0
fi
$IPT -P INPUT DROP
$IPT -P OUTPUT DROP
$IPT -P FORWARD DROP
echo "Create and populate custom rule chains ..."
$IPT -N bad_packets
$IPT -N bad_tcp_packets
$IPT -N icmp_packets
$IPT -N udp_inbound
$IPT -N udp_outbound
$IPT -N tcp_inbound
$IPT -N tcp_outbound
$IPT -A bad_packets -p ALL -i $INET_IFACE -s $LOCAL_NET -j LOG \
    --log-prefix "Illegal source: "
$IPT -A bad_packets -p ALL -i $INET_IFACE -s $LOCAL_NET -j DROP
$IPT -A bad_packets -p ALL -m state --state INVALID -j LOG \
    --log-prefix "Invalid packet: "
$IPT -A bad_packets -p ALL -m state --state INVALID -j DROP
$IPT -A bad_packets -p tcp -j bad_tcp_packets
$IPT -A bad_packets -p ALL -j RETURN
$IPT -A bad_tcp_packets -p tcp -i $LOCAL_IFACE -j RETURN
$IPT -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG \
    --log-prefix "New not syn: "
$IPT -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP
$IPT -A bad_tcp_packets -p tcp --tcp-flags ALL NONE -j LOG \
    --log-prefix "Stealth scan: "
$IPT -A bad_tcp_packets -p tcp --tcp-flags ALL NONE -j DROP
$IPT -A bad_tcp_packets -p tcp --tcp-flags ALL ALL -j LOG \
    --log-prefix "Stealth scan: "
$IPT -A bad_tcp_packets -p tcp --tcp-flags ALL ALL -j DROP
$IPT -A bad_tcp_packets -p tcp --tcp-flags ALL FIN,URG,PSH -j LOG \
    --log-prefix "Stealth scan: "
$IPT -A bad_tcp_packets -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
$IPT -A bad_tcp_packets -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j LOG \
    --log-prefix "Stealth scan: "
$IPT -A bad_tcp_packets -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
$IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,RST SYN,RST -j LOG \
    --log-prefix "Stealth scan: "
$IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
$IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,FIN SYN,FIN -j LOG \
    --log-prefix "Stealth scan: "
$IPT -A bad_tcp_packets -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
$IPT -A bad_tcp_packets -p tcp -j RETURN
$IPT -A icmp_packets --fragment -p ICMP -j LOG \
    --log-prefix "ICMP Fragment: "
$IPT -A icmp_packets --fragment -p ICMP -j DROP
$IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j DROP
$IPT -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT
$IPT -A icmp_packets -p ICMP -j RETURN
$IPT -A udp_inbound -p UDP -s 0/0 --destination-port 137 -j DROP
$IPT -A udp_inbound -p UDP -s 0/0 --destination-port 138 -j DROP
$IPT -A udp_inbound -p UDP -s 0/0 --source-port 67 --destination-port 68 \
     -j ACCEPT
$IPT -A udp_inbound -p UDP -j RETURN
$IPT -A udp_outbound -p UDP -s 0/0 -j ACCEPT
$IPT -A tcp_inbound -p TCP -s 0/0 --destination-port 22 -j ACCEPT
$IPT -A tcp_inbound -p TCP -j RETURN
$IPT -A tcp_outbound -p TCP -s 0/0 -j ACCEPT
echo "Process INPUT chain ..."
$IPT -A INPUT -p ALL -i $LO_IFACE -j ACCEPT
$IPT -A INPUT -p ALL -j bad_packets
$IPT -A INPUT -p ALL -d 224.0.0.1 -j DROP
$IPT -A INPUT -p ALL -i $LOCAL_IFACE -s $LOCAL_NET -j ACCEPT
$IPT -A INPUT -p ALL -i $LOCAL_IFACE -d $LOCAL_BCAST -j ACCEPT
$IPT -A INPUT -p ALL -i $INET_IFACE -m state --state ESTABLISHED,RELATED \
     -j ACCEPT
$IPT -A INPUT -p TCP -i $INET_IFACE -j tcp_inbound
$IPT -A INPUT -p UDP -i $INET_IFACE -j udp_inbound
$IPT -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets
$IPT -A INPUT -m pkttype --pkt-type broadcast -j DROP
$IPT -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
    --log-prefix "INPUT packet died: "
echo "Process FORWARD chain ..."
$IPT -A FORWARD -p ALL -j bad_packets
$IPT -A FORWARD -p tcp -i $LOCAL_IFACE -j tcp_outbound
$IPT -A FORWARD -p udp -i $LOCAL_IFACE -j udp_outbound
$IPT -A FORWARD -p ALL -i $LOCAL_IFACE -j ACCEPT
$IPT -A FORWARD -i $INET_IFACE -m state --state ESTABLISHED,RELATED \
     -j ACCEPT
$IPT -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG \
    --log-prefix "FORWARD packet died: "
echo "Process OUTPUT chain ..."
$IPT -A OUTPUT -m state -p icmp --state INVALID -j DROP
$IPT -A OUTPUT -p ALL -s $LO_IP -j ACCEPT
$IPT -A OUTPUT -p ALL -o $LO_IFACE -j ACCEPT
$IPT -A OUTPUT -p ALL -s $LOCAL_IP -j ACCEPT
$IPT -A OUTPUT -p ALL -o $LOCAL_IFACE -j ACCEPT
$IPT -A OUTPUT -p ALL -o $INET_IFACE -j ACCEPT
$IPT -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
    --log-prefix "OUTPUT packet died: "
echo "Load rules for nat table ..."
$IPT -t nat -A POSTROUTING -o $INET_IFACE -j MASQUERADE
echo "Load rules for mangle table ..."





 ./comment-out.bat /etc/grub.d/40_custom
exec tail -n +3 $0
menuentry 'openbsd ' {
    set root='hd0,msdos0'
    chainloader +1
}



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
}









2015年6月10日水曜日

clamav

https://wiki.archlinux.org/index.php/ClamAV をみて

1) pacman -S clamav

2) freshclam

3)
WARNING: Clamd was NOT notified: Can't connect to clamd through /var/lib/clamav/clamd.sock: No such file or directory
がでたので
 
# touch /var/lib/clamav/clamd.sock
# chown clamav:clamav /var/lib/clamav/clamd.sock
 
4)もう一度 freshclam すると
 ClamAV update process started at Wed Jun 10 01:33:35 2015
main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
daily.cvd is up to date (version: 20557, sigs: 1423118, f-level: 63, builder: neo)
bytecode.cvd is up to date (version: 256, sigs: 45, f-level: 63, builder: dgoddard)

5)で
wget -O- http://www.eicar.org/download/eicar.com.txt | clamscan -
したら 
 
 
stdin: Eicar-Test-Signature FOUND

----------- SCAN SUMMARY -----------
Known viruses: 3841799
Engine version: 0.98.7
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 40.088 sec (0 m 40 s)
なって clamscan の テストはOK。

 
6)# systemctl start clamd
Job for clamd.service failed. See "systemctl status clamd.service" and "journalctl -xe" for details.
といけない。



 
今 /etc/clamav/freshclam.conf は
DatabaseMirror database.clamav.net
NotifyClamd /etc/clamav/clamd.conf
 
また 今 /etc/clamav/clamd.conf は
LogFile /var/log/clamav/clamd.log
LogTime yes
PidFile /run/clamav/clamd.pid
TemporaryDirectory /tmp
LocalSocket /var/lib/clamav/clamd.sock
User clamav
 
 
しかし 再起動して
systemctl start clamd
がうまく動かない。
 


 

で clamd , clamdscan は 今はあきらめて
 
 
 
 
clamscan.bat (clamscanは遅いのですが)
 
 http://www.cloud-memo.com/2014/04/clamscan.html  をみて
 

#!/bin/sh
## Scan
clamscan -ri $1    > /var/log/clamav/scan.log
## Mail Send
cat /var/log/clamav/scan.log | mail -s "Scan Report" root@localhost
exit
 
 
 
 
 
 
 
http://www.kernel-panic.it/openbsd/mail/mail6.html
をみて
 
 
/etc/freshclam.conf
# Comment or remove the line below.
#Example
DatabaseDirectory /var/db/clamav
DatabaseOwner  _clamav
DNSDatabaseInfo  current.cvd.clamav.net
DatabaseMirror  db.it.clamav.net
DatabaseMirror  database.clamav.net
MaxAttempts  3
checks   24

/etc/clamd.conf
# Comment or remove the line below. 
#Example 
DatabaseDirectory  /var/db/clamav 
TCPAddr 127.0.0.1 
TCPSocket 3310 
User _clamav 
LogSyslog yes 
LogFacility LOG_MAIL

 
pacman -S cronie

crontab -eを
16 * * * * /usr/bin/freshclam >/dev/null 2>&1
とする。





2015年3月18日水曜日

エラー key firefox

1)
エラー: key "7A4E76095D8A52E4" could not be looked up remotely
エラー: キーリングに必要なキーがありません
エラー: 処理を完了できませんでした (予期しないエラー)
エラーが発生したため、パッケージは更新されませんでした。


https://archlinuxjp.kusakata.com/wiki/Pacman-key?rdfrom=https%3A%2F%2Fwiki.archlinux.org%2Findex.php%3Ftitle%3DPacman-key_%28%25E6%2597%25A5%25E6%259C%25AC%25E8%25AA%259E%29%26redirect%3Dno#5.E3.81.A4.E3.81.AE.E3.83.9E.E3.82.B9.E3.82.BF.E3.83.BC.E3.82.AD.E3.83.BC.E3.82.92.E6.A4.9C.E8.A8.BC.E3.81.99.E3.82.8B

をみて

# pacman-key --init
 
# pacman-key --populate archlinux
 
==> archlinux.gpg からキーを追加...
==> キーリングの信頼されたキーに署名...
  -> キーに署名 0E8B644079F599DFC1DDC3973348882F6AC6A4C2...
  -> キーに署名 684148BB25B49E986A4944C55184252D824B18E8...
  -> キーに署名 44D4A033AC140143927397D47EFD567D4C7EA887...
  -> キーに署名 27FFC4769E19F096D41D9265A04F9397CDFD6BB0...
  -> キーに署名 AB19265E5D7D20687D303246BA1DFB64FFF979E7...
==> 所有者信頼値をインポート...
==> キーリングの破棄されたキーを無効化...
  -> キー F5A361A3A13554B85E57DDDAAF7EF7873CFD4BB6 を無効化...
  -> キー 7FA647CD89891DEDC060287BB9113D1ED21E1A55 を無効化...
  -> キー D4DE5ABDE2A7287644EAC7E36D1A9E70E19DAA50 を無効化...
  -> キー BC1FBE4D2826A0B51E47ED62E2539214C6C11350 を無効化...
  -> キー 4A8B17E20B88ACA61860009B5CED81B7C2E5C0D2 を無効化...
  -> キー 63F395DE2D6398BBE458F281F2DBB4931985A992 を無効化...
  -> キー 0B20CA1931F5DA3A70D0F8D2EA6836E1AB441196 を無効化...
  -> キー 8F76BEEA0289F9E1D3E229C05F946DED983D4366 を無効化...
  -> キー 66BD74A036D522F51DD70A3C7F2A16726521E06D を無効化...
  -> キー 81D7F8241DB38BC759C80FCE3A726C6170E80477 を無効化...
  -> キー E7210A59715F6940CF9A4E36A001876699AD6E84 を無効化...
==> 信用データベースを更新...
gpg: 次回の信用データベース検査は、2016-01-22です

# pacman-key --refresh-keys





 
2)firefox 立ち上がらない 
pacman -Syuしよう。
operaをいれておこう。 
 
 
 
これでも 
 ●●●●●●●●●●●●
 $ firefox 
XPCOMGlueLoad error for file /usr/lib/firefox/libxul.so:
libvpx.so.2: cannot open shared object file: No such file or directory
Couldn't load XPCOM.


のときは


# cd /usr/lib/
# ln -s libvpx.so.1.3.0 libvpx.so.2

 
 



2015年2月24日火曜日

teamviewer と rsync+ssh と ssh -Y  




1) 下の図は 自宅のtahr  から遠隔地のarch にはいりました。
teamviewer は vnc over sshと比べると 早い早い。
ssh -Yは ある特定のアプリしか立ち上がらなく、x-windows全体は無理です。

teamviewer は なんたって
 Easy to use remote desktop sharing / presentation and file transfer application that works  behind routers and firewalls.
の能力があります。
つまり 2つのPCでteamviewerをうごかしておれば ポートがひらいてなくとも 
firewallの向こうでもいいわけです。

(http://okwave.jp/qa/q6426998.htmlでは
TeamViewerがIPアドレスやファイアウォール(FW)を意識しなくて済むのは,
被操作側PCに相手が侵入するのではなく,
被操作側が自主的にインターネットに出て行って,
TeamViewerルーティングサーバ上でIDとパスワードを発行してもらい,
相手がやってくる (セッションの確立)のを同サーバ上で待つからです


 

2)ssh+rsync

sshdは 、インターネットに出て行って相手がやってくる のを待ってたりしません。
だから ファイアウォール越にsshを使うには、
teamviewerではいって そこからあらためてssh+rsync をします。

 rsync -a --delete -e ssh /home/t t@a.mydns.jp:/home/t/k
^CKilled by signal 2.
rsync error: unexplained error (code 255) at rsync.c(632) [sender=3.1.1]
rsync: [sender] write error: Broken pipe (32)

だった。
バカみたいな話だが、 両方のPCにrsyncをいれたら解決。



3)ssh -Y
遠隔地のPCでは aurのteamviewer10 がはいりません。
しかたなく windows用のTeamViewer_Setup_ja.exeをダウンロードして
wine TeamViewer_Setup_ja.exeをしますと、ひきづられてmono と geckoがはいり、teamviewer10のアイコンがでますが、たちあがりません。

遠隔地のarch のteamviewer9は、自宅のarchのteamviewer10には接続できません。

しょうがないので遠隔地では ssh -Y を使います。
つまり、  遠隔地でssh -Y t@a.mydns.jp です。


なお  /etc/ssh/sshd_config ですが

遠隔地のは $ cat /etc/ssh/sshd_config
AuthorizedKeysFile    .ssh/authorized_keys
ChallengeResponseAuthentication no
UsePAM yes
PrintMotd no # pam does that
UsePrivilegeSeparation sandbox        # Default for new installations.
Subsystem    sftp    /usr/lib/ssh/sftp-server
X11Forwarding yes


自宅のはcat /etc/ssh/sshd_config
Port 22
Protocol 2

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key

UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120

#PermitRootLogin yes

StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no

PermitEmptyPasswords no
ChallengeResponseAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes



ssh -Y t@a.mydns.jpしたあと、midoriで
遠隔地のPCにmidoriが立ち上がってきます。



 
 
 
 
 
 
 















 





2015年1月7日水曜日

dice

cybergateで 追随するには



diceですが./diced | nkf -uwして日本語が見えるようにして
1番目に setupし
 
 
2番目に addて

[ オフライン ]
(0)No (1)Yes
番号>1

そしてから dicedを実行させるといいです。
詳細はネットで調べて下さい。

2014年12月28日日曜日

Windows8.1のフォルダを mount する。

これはまさに
http://www.atmarkit.co.jp/flinux/rensai/linuxtips/a004mountcifs.html
そのもので

cat mount-windows81-common.bat

mount -t cifs //192.168.100.102/common /mnt81  -o username=user1

です。

もちろん windows81で ローカルアカウントuser1をつくってます。





dvdstyler