Автор Тема: Не отрабатывает правило iptables (Решено)  (Прочитано 4282 раз)

Оффлайн lone_wolf

  • Участник
  • *
  • Сообщений: 26
Всем привет, вобщем стала задача ограничить доступ к серверу в определеные часы и дни, погуглил и наткнулся на модель iptables time. пишу тестовое правило на своем десктопе (пока разбираюсь) :

iptables -I INPUT -p tcp --dport 3328 -m time --timestart 22:53 --timestop 23:29 --weekdays Wednesday -j DROP\

жду наступления времени и вижу нормальный доступ по тестовому порту. Подскаите может я что то не так делаю ?
« Последнее редактирование: 07.09.2013 18:46:11 от lone_wolf »

Оффлайн ruslandh

  • Поспешай не торопясь !
  • Модератор глобальный
  • *****
  • Сообщений: 32 361
  • Учиться .... Телепатами не рождаются, ими ....
Re: Не отрабатывает правило iptables
« Ответ #1 : 06.09.2013 00:34:24 »
Не знаю нюансов, но тут  написано
Цитировать
iptables -A INPUT -p tcp -d 80 -m time \
                 --timestart 04:00 --timestop 06:30 --days Fri \
                 --syn -j REJECT


Следует отметить, что все три ключа -timestart, -timestop и -days   обязательно должны быть включены в правило.
Тупо смотрю на ваше правило и не вижу параметра  -days, есть --weekdays , но это может оказаться неравнозначно.
« Последнее редактирование: 06.09.2013 00:44:50 от ruslandh »

Оффлайн lone_wolf

  • Участник
  • *
  • Сообщений: 26
Re: Не отрабатывает правило iptables
« Ответ #2 : 06.09.2013 17:47:51 »
по началу я именно оттуда и брал, но вот что получаю в ответ :
[root@host-53 ~]# iptables -I OUTPUT -p tcp --dport 80 -m time --timestart 16:46 --timestop 17:00 --days Fri -j DROP
iptables v1.4.18: unknown option "--days"
Try `iptables -h' or 'iptables --help' for more information.

погуглил посмотрел в блогах люди используют --weekdays

Оффлайн Peter_

  • Участник
  • *
  • Сообщений: 105
Re: Не отрабатывает правило iptables
« Ответ #3 : 06.09.2013 21:53:19 »
Сам я в этом не разбираюсь, но вот ещё ссылка, очень не новая.
http://www.xakep.ru/magazine/xs/047/074/1.asp

Пётр.
Пётр.

Оффлайн ruslandh

  • Поспешай не торопясь !
  • Модератор глобальный
  • *****
  • Сообщений: 32 361
  • Учиться .... Телепатами не рождаются, ими ....
Re: Не отрабатывает правило iptables
« Ответ #4 : 06.09.2013 22:28:05 »
Короче - русский man от iptables - в этой части устарел, читаю
man iptables-extensions
Я в английском не силён, но там про часовой пояс что-то:
Спойлер
time
       This matches if the packet arrival time/date is within a  given  range.
       All  options  are optional, but are ANDed when specified. All times are
       interpreted as UTC by default.

       --datestart YYYY[-MM[-DD[Thh[:mm[:ss]]]]]

       --datestop YYYY[-MM[-DD[Thh[:mm[:ss]]]]]
              Only match during the given time, which must be in ISO 8601  "T"
              notation.   The  possible  time  range is 1970-01-01T00:00:00 to
              2038-01-19T04:17:07.

              If --datestart or --datestop are not specified, it will  default
              to 1970-01-01 and 2038-01-19, respectively.

       --timestart hh:mm[:ss]

       --timestop hh:mm[:ss]
              Only  match during the given daytime. The possible time range is
              00:00:00 to 23:59:59. Leading zeroes are allowed (e.g.  "06:03")
              and correctly interpreted as base-10.

       [!] --monthdays day[,day...]
              Only match on the given days of the month. Possible values are 1
              to 31. Note that specifying 31  will  of  course  not  match  on
              months  which  do  not have a 31st day; the same goes for 28- or
              29-day February.

       [!] --weekdays day[,day...]
              Only match on the given weekdays. Possible values are Mon,  Tue,
              Wed,  Thu,  Fri,  Sat, Sun, or values from 1 to 7, respectively.
              You may also use two-character variants (Mo, Tu, etc.).

       --contiguous
              When --timestop is smaller than --timestart value, match this as
              a single time period instead distinct intervals.  See EXAMPLES.
   
   --kerneltz
              Use  the  kernel  timezone instead of UTC to determine whether a
              packet meets the time regulations.

       About kernel timezones: Linux keeps the system time in UTC, and  always
       does  so.   On boot, system time is initialized from a referential time
       source. Where this time source has no timezone information, such as the
       x86 CMOS RTC, UTC will be assumed. If the time source is however not in
       UTC, userspace should provide the correct system time and  timezone  to
       the kernel once it has the information.

       Local  time  is  a  feature on top of the (timezone independent) system
       time. Each process has its own idea of local time, specified via the TZ
       environment variable. The kernel also has its own timezone offset vari-
       able. The TZ userspace environment variable specifies how the UTC-based
       system time is displayed, e.g. when you run date(1), or what you see on
       your desktop clock.  The TZ string may resolve to different offsets  at
       different  dates,  which  is what enables the automatic time-jumping in
       userspace. when DST changes. The kernel's timezone offset  variable  is
       used  when  it  has  to  convert  between  non-UTC sources, such as FAT
       filesystems, to UTC (since the latter is what the rest  of  the  system
       uses).

       The  caveat  with  the  kernel timezone is that Linux distributions may
       ignore to set the kernel timezone, and  instead  only  set  the  system
       time.  Even if a particular distribution does set the timezone at boot,
       it is usually does not keep the kernel timezone offset - which is  what
       changes  on DST - up to date.  ntpd will not touch the kernel timezone,
       so running it will not resolve the issue. As such, one may encounter  a
       timezone that is always +0000, or one that is wrong half of the time of
       the year. As such, using --kerneltz is highly discouraged.


       EXAMPLES. To match on weekends, use:

              -m time --weekdays Sa,Su

       Or, to match (once) on a national holiday block:

              -m time --datestart 2007-12-24 --datestop 2007-12-27

       Since the stop time is actually inclusive, you would need the following
       stop time to not match the first second of the new day:

              -m      time     --datestart     2007-01-01T17:00     --datestop
              2007-01-01T23:59:59


       During lunch hour:

              -m time --timestart 12:30 --timestop 13:30

       The fourth Friday in the month:

              -m time --weekdays Fr --monthdays 22,23,24,25,26,27,28

       (Note that this exploits a certain mathematical  property.  It  is  not
       possible  to  say "fourth Thursday OR fourth Friday" in one rule. It is
       possible with multiple rules, though.)

       Matching across days might not do what is expected.  For instance,

              -m time --weekdays Mo --timestart 23:00  --timestop  01:00  Will
              match  Monday,  for  one  hour from midnight to 1 a.m., and then
              again for another hour from 23:00 onwards.  If this is unwanted,
              e.g.  if  you  would like 'match for two hours from Montay 23:00
              onwards' you need to also specify the --contiguous option in the
              example above.



Оффлайн ruslandh

  • Поспешай не торопясь !
  • Модератор глобальный
  • *****
  • Сообщений: 32 361
  • Учиться .... Телепатами не рождаются, ими ....
Re: Не отрабатывает правило iptables
« Ответ #5 : 06.09.2013 22:39:19 »
Короче, возможно время нужно указывать по-Гринвичу.

All times are  interpreted as UTC by default.
По-умолчанию считается что часовой пояс  -  UTC  (Гринвич)
« Последнее редактирование: 06.09.2013 22:46:41 от ruslandh »

Оффлайн lone_wolf

  • Участник
  • *
  • Сообщений: 26
Re: Не отрабатывает правило iptables
« Ответ #6 : 07.09.2013 03:42:46 »
Will
              match  Monday,  for  one  hour from midnight to 1 a.m., and then
              again for another hour from 23:00 onwards.  If this is unwanted,
              e.g.  if  you  would like 'match for two hours from Montay 23:00
              onwards' you need to also specify the --contiguous option in the
              example above.
ну в системе точное время я проверил :-(

Оффлайн ruslandh

  • Поспешай не торопясь !
  • Модератор глобальный
  • *****
  • Сообщений: 32 361
  • Учиться .... Телепатами не рождаются, ими ....
Re: Не отрабатывает правило iptables
« Ответ #7 : 07.09.2013 07:55:47 »
Не - я не про точность, а про то, какое время задают параметры --timestart и --timestop.
Возможно, ваши  22:53 - это 22:53 по гринвичу (UTC),  что соответствует 02:53 Москвы.

Оффлайн lone_wolf

  • Участник
  • *
  • Сообщений: 26
Re: Не отрабатывает правило iptables
« Ответ #8 : 07.09.2013 16:16:00 »
вручную указал что часовой пояс берем по киеву  и провел синхронизауию... не помогло  :(

Оффлайн ksa

  • Модератор глобальный
  • *****
  • Сообщений: 9 049
Re: Не отрабатывает правило iptables
« Ответ #9 : 07.09.2013 17:46:13 »
Укажите время в правиле по Гинвичу (UTC) (ваше местное время - 3 часа = время по Гринвичу, которое и нужно вписать в правило) и всё будет работать. В мане же чётко об этом написано. У себя проверил локально (на t6) -- всё работает, как и должно. Единственное отличие моего правила в том, что использовал -A вместо -I.

Оффлайн lone_wolf

  • Участник
  • *
  • Сообщений: 26
Re: Не отрабатывает правило iptables
« Ответ #10 : 07.09.2013 18:45:10 »
Огромное спасибо мужики   :D вьехал.... заработало ... Так все пора мне с бронепоизда спригивать   ;D

З.Ы время можно указывать не только по UTC, но и время ядра операционной системы для этого нужно юзать:
--kerneltz
« Последнее редактирование: 07.09.2013 20:06:22 от lone_wolf »